easter.awk 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. BEGIN {
  2. y=2016; # change to the appropriate year !
  3. lang=ENVIRON["LANG"]
  4. easter["C"]="Easter"
  5. easter["fr_FR.ISO8859-1"]="P?ques"
  6. easter["it_IT.ISO8859-1"]="Pasqua"
  7. easter["es_ES.ISO8859-1"]="Pascua"
  8. easter["de_DE.ISO8859-1"]="Ostersonntag"
  9. ascension["C"]="Ascension Day"
  10. ascension["fr_FR.ISO8859-1"]="Ascension"
  11. ascension["it_IT.ISO8859-1"]="Ascensione"
  12. ascension["es_ES.ISO8859-1"]="Ascension"
  13. ascension["de_DE.ISO8859-1"]="Christi Himmelfahrt"
  14. whit["C"]="Whit Sunday"
  15. whit["fr_FR.ISO8859-1"]="Pentec?te"
  16. whit["it_IT.ISO8859-1"]="Spirito Sancto"
  17. whit["es_ES.ISO8859-1"]="Pentecost?s"
  18. whit["de_DE.ISO8859-1"]="Pfingstsonntag"
  19. # Formula to calculate the date of Easter
  20. g=y%19;
  21. c=int(y/100);
  22. c4=int(c/4);
  23. e=int((8*c+13)/25);
  24. h=(19*g+c-c4-e+15)%30;
  25. k=int(h/28);
  26. p=int(29/(h+1));
  27. q=int((21-g)/11);
  28. i=(k*p*q-1)*k+h;
  29. b=int(y/4)+y;
  30. j1=b+i+2+c4-c;
  31. j2=j1%7;
  32. r=28+i-j2;
  33. m=int(r/32)+3;
  34. d=r-31*(m-3);
  35. # Creating an appointment in XAPIA format for Easter
  36. sdate=sprintf("%.4d%.2d%.2dT004100Z",d,m,y);
  37. fdate=sprintf("%.4d%.2d%.2dT004200Z",d,m,y);
  38. appt="easter_"y;
  39. printf("\n\n") >appt
  40. print "\t** Calendar Appointment **" >appt
  41. print "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Entry Delimiter//EN:string:begin">appt;
  42. printf("-//XAPIA/CSA/ENTRYATTR//NONSGML Start Date//EN:datetime:%s\n",sdate)>appt;
  43. print "-//XAPIA/CSA/ENTRYATTR//NONSGML Type//EN:uinteger:0">appt;
  44. print "-//XAPIA/CSA/ENTRYATTR//NONSGML Subtype//EN:string:-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Appointment//EN">appt;
  45. print "-//XAPIA/CSA/ENTRYATTR//NONSGML Classification//EN:uinteger:0">appt;
  46. printf("-//XAPIA/CSA/ENTRYATTR//NONSGML End Date//EN:datetime:%s\n",fdate)>appt;
  47. print "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Show Time//EN:sinteger:0">appt;
  48. printf("-//XAPIA/CSA/ENTRYATTR//NONSGML Summary//EN:string: %s %.4d\n",easter[lang],y)>appt;
  49. print "-//XAPIA/CSA/ENTRYATTR//NONSGML Status//EN:uinteger:2304">appt;
  50. printf("-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Repeat Type//EN:sinteger:0\n")>appt;
  51. printf("-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Repeat Times//EN:uinteger:0\n")>appt;
  52. print "-//XAPIA/CSA/ENTRYATTR//NONSGML Audio Reminder//EN:reminder:300:">appt;
  53. print "-//XAPIA/CSA/ENTRYATTR//NONSGML Popup Reminder//EN:reminder:300:">appt;
  54. print "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Repeat Occurrence Number//EN:sinteger:-1">appt;
  55. print "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Repeat Interval//EN:uinteger:0">appt;
  56. print "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Entry Delimiter//EN:string:end">appt;
  57. printf("\tDate: %s/%s/%s\n",m,d,y)>appt;
  58. printf("\tStart: 0241\n",shour,smin)>appt
  59. printf("\tEnd: 0242\n",fhour,fmin)>appt
  60. printf("\tRepeat: One Time\n")>appt;
  61. printf("\tFor: 0\n")>appt;
  62. printf("\tWhat: %s %.4d\n",easter[lang],y)>appt;
  63. printf("\t")>appt;
  64. # Ascension day is 40 days after easter
  65. aday=r+39;
  66. # print aday; # for debugging purpose only !
  67. m=3;
  68. if (aday>31) {aday-=31;m++ }
  69. if (aday>30) {aday-=30;m++ }
  70. if (aday>31) {aday-=31;m++}
  71. if (aday>30) {aday-=30;m++}
  72. sdate=sprintf("%.4d%.2d%.2dT004100Z",aday,m,y);
  73. fdate=sprintf("%.4d%.2d%.2dT004200Z",aday,m,y);
  74. appt="ascension_"y;
  75. printf("\n\n") >appt
  76. print "\t** Calendar Appointment **" >appt
  77. print "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Entry Delimiter//EN:string:begin">appt;
  78. printf("-//XAPIA/CSA/ENTRYATTR//NONSGML Start Date//EN:datetime:%s\n",sdate)>appt;
  79. print "-//XAPIA/CSA/ENTRYATTR//NONSGML Type//EN:uinteger:0">appt;
  80. print "-//XAPIA/CSA/ENTRYATTR//NONSGML Subtype//EN:string:-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Appointment//EN">appt;
  81. print "-//XAPIA/CSA/ENTRYATTR//NONSGML Classification//EN:uinteger:0">appt;
  82. printf("-//XAPIA/CSA/ENTRYATTR//NONSGML End Date//EN:datetime:%s\n",fdate)>appt;
  83. print "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Show Time//EN:sinteger:0">appt;
  84. printf("-//XAPIA/CSA/ENTRYATTR//NONSGML Summary//EN:string: %s %.4d\n",ascension[lang],y)>appt;
  85. print "-//XAPIA/CSA/ENTRYATTR//NONSGML Status//EN:uinteger:2304">appt;
  86. printf("-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Repeat Type//EN:sinteger:0\n")>appt;
  87. printf("-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Repeat Times//EN:uinteger:0\n")>appt;
  88. print "-//XAPIA/CSA/ENTRYATTR//NONSGML Audio Reminder//EN:reminder:300:">appt;
  89. print "-//XAPIA/CSA/ENTRYATTR//NONSGML Popup Reminder//EN:reminder:300:">appt;
  90. print "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Repeat Occurrence Number//EN:sinteger:-1">appt;
  91. print "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Repeat Interval//EN:uinteger:0">appt;
  92. print "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Entry Delimiter//EN:string:end">appt;
  93. printf("\tDate: %s/%s/%s\n",m,aday,y)>appt;
  94. printf("\tStart: 0241\n",shour,smin)>appt
  95. printf("\tEnd: 0242\n",fhour,fmin)>appt
  96. printf("\tRepeat: One Time\n")>appt;
  97. printf("\tFor: 0\n")>appt;
  98. printf("\tWhat: %s %.4d\n",ascension[lang],y)>appt;
  99. printf("\t")>appt;
  100. # Whit Monday is 50 days after easter
  101. wday=r+48;
  102. m=3;
  103. if (wday>31) {wday-=30;m++}
  104. if (wday>30) {wday-=30;m++}
  105. if (wday>31) {wday-=31;m++}
  106. if (wday>30) {wday-=30;m++}
  107. sdate=sprintf("%.4d%.2d%.2dT004100Z",wday,m,y);
  108. fdate=sprintf("%.4d%.2d%.2dT004200Z",wday,m,y);
  109. appt="whit_"y;
  110. printf("\n\n") >appt
  111. print "\t** Calendar Appointment **" >appt
  112. print "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Entry Delimiter//EN:string:begin">appt;
  113. printf("-//XAPIA/CSA/ENTRYATTR//NONSGML Start Date//EN:datetime:%s\n",sdate)>appt;
  114. print "-//XAPIA/CSA/ENTRYATTR//NONSGML Type//EN:uinteger:0">appt;
  115. print "-//XAPIA/CSA/ENTRYATTR//NONSGML Subtype//EN:string:-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Appointment//EN">appt;
  116. print "-//XAPIA/CSA/ENTRYATTR//NONSGML Classification//EN:uinteger:0">appt;
  117. printf("-//XAPIA/CSA/ENTRYATTR//NONSGML End Date//EN:datetime:%s\n",fdate)>appt;
  118. print "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Show Time//EN:sinteger:0">appt;
  119. printf("-//XAPIA/CSA/ENTRYATTR//NONSGML Summary//EN:string: %s %.4d\n",whit[lang],y)>appt;
  120. print "-//XAPIA/CSA/ENTRYATTR//NONSGML Status//EN:uinteger:2304">appt;
  121. printf("-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Repeat Type//EN:sinteger:0\n")>appt;
  122. printf("-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Repeat Times//EN:uinteger:0\n")>appt;
  123. print "-//XAPIA/CSA/ENTRYATTR//NONSGML Audio Reminder//EN:reminder:300:">appt;
  124. print "-//XAPIA/CSA/ENTRYATTR//NONSGML Popup Reminder//EN:reminder:300:">appt;
  125. print "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Repeat Occurrence Number//EN:sinteger:-1">appt;
  126. print "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Repeat Interval//EN:uinteger:0">appt;
  127. print "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Entry Delimiter//EN:string:end">appt;
  128. printf("\tDate: %s/%s/%s\n",m,wday,y)>appt;
  129. printf("\tStart: 0241\n",shour,smin)>appt
  130. printf("\tEnd: 0242\n",fhour,fmin)>appt
  131. printf("\tRepeat: One Time\n")>appt;
  132. printf("\tFor: 0\n")>appt;
  133. printf("\tWhat: %s %.4d\n",whit[lang],y)>appt;
  134. printf("\t")>appt;
  135. }
  136. # We can also calculate the date of Pentecost (Whit Sunday/Monday) = Easter +50 days
  137. # and of Ascension Day = Easter + 4O days
  138. # To write to files in awk, it is enough to do print(f) something > FILE