fork download
  1. // w JS miesiące zaczynają się od 0 tzn że styczen ma wartosc 0, luty 1 itd.
  2. print("Czy 8 kwietnia 2012 będzie wolne? - "+CzySwieto(new Date(2012,3,8)).toString());
  3.  
  4. print("Czy 22 listopada 2010 będzie wolne? - "+CzySwieto(new Date(2010, 10, 22)).toString());
  5.  
  6. print("Czy 26 grudnia 2011 będzie wolne? - "+CzySwieto(new Date(2011, 11, 26)).toString());
  7.  
  8. function CzySwieto(dt)
  9. {
  10.  
  11. switch (dt.getMonth())
  12. {
  13. case 0:
  14. {
  15. if (dt.getDate() == 1 || dt.getDate() == 6)
  16. {
  17. return true;
  18. }
  19. break;
  20. }
  21. case 4:
  22. {
  23. if (dt.getDate() == 1 || dt.getDate() == 3)
  24. {
  25. return true;
  26. }
  27. break;
  28. }
  29. case 7:
  30. {
  31. if (dt.getDate() == 15)
  32. {
  33. return true;
  34. }
  35. break;
  36. }
  37. case 10:
  38. {
  39. if (dt.getDate() == 1 || dt.getDate() == 11)
  40. {
  41. return true;
  42. }
  43. break;
  44. }
  45. case 11:
  46. {
  47. if (dt.getDate() == 25 || dt.getDate() == 26)
  48. {
  49. return true;
  50. }
  51. break;
  52. }
  53. }
  54.  
  55. if (dt.getMonth() >= 3 || dt.getMonth() <= 6)
  56. {
  57. //obliczanie Wielkanocy
  58. a = dt.getFullYear() % 19;
  59. b = Math.floor(dt.getFullYear() / 100);
  60. c = dt.getFullYear() % 100;
  61. d = Math.floor(b / 4);
  62. e = b % 4;
  63. f = Math.floor((b + 8) / 25);
  64. g = Math.floor((b - f + 1) / 3);
  65. h = (19 * a + b - d - g + 15) % 30;
  66. i = Math.floor(c / 4);
  67. k = c % 4;
  68. l= (32+2*e+2*i-h-k)%7;
  69. m = Math.floor((a+11*h+22*l)/451);
  70. p = (h + l - 7 * m + 114) % 31;
  71. dzien = p + 1;
  72. miesiac = Math.floor((h + l - 7 * m + 114) / 31);
  73.  
  74. miesiac--;//w JS miesiące zaczynają się od 0
  75.  
  76. Wielkanoc = new Date(dt.getFullYear(), miesiac, dzien);
  77. Wielkanoc2 = new Date(dt.getFullYear(), miesiac, dzien+1);
  78. ZDS = new Date(dt.getFullYear(), miesiac, dzien+49);
  79. BC = new Date(dt.getFullYear(), miesiac, dzien+60);
  80.  
  81. if (dt.valueOf() == Wielkanoc.valueOf() || dt.valueOf() == Wielkanoc2.valueOf() || dt.valueOf() == ZDS.valueOf() || dt.valueOf() == BC.valueOf())
  82. {
  83. return true;
  84. }
  85. }
  86. return false;
  87. }
Success #stdin #stdout 0.01s 29840KB
stdin
Standard input is empty
stdout
Czy 8 kwietnia 2012 będzie wolne? - true
Czy 22 listopada 2010 będzie wolne? - false
Czy 26 grudnia 2011 będzie wolne? - true