You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.4 KiB

2 months ago
  1. /* cal.mod - print an ASCII calendar of the given year */
  2. /* Written in GNU MathProg by Andrew Makhorin <mao@gnu.org> */
  3. param year, integer, >= 0001, <= 3999, default 2010;
  4. param first_day{m in 1..12}, integer, >= 0, <= 6, :=
  5. time2str(str2time(year & "-" & m & "-01", "%Y-%m-%d"), "%w");
  6. param days_in_month{m in 1..12}, integer, >= 28, <= 31, :=
  7. (str2time(year + (if m < 12 then 0 else 1) & "-" &
  8. (if m < 12 then m+1 else 1) & "-01", "%Y-%m-%d") -
  9. str2time(year & "-" & m & "-01", "%Y-%m-%d")) / 86400;
  10. param foo{m in 1..12, k in 0..5, d in 0..6}, integer, :=
  11. 7 * k + d + 1 - first_day[m];
  12. param cal{m in 1..12, k in 0..5, d in 0..6}, integer, :=
  13. if 1 <= foo[m,k,d] and foo[m,k,d] <= days_in_month[m] then
  14. foo[m,k,d];
  15. printf "\n";
  16. printf "%33s%04d\n", "", year;
  17. printf "\n";
  18. for {t in 1..12 by 3}
  19. { for {m in t..t+2}
  20. { printf "%7s%-14s", "", time2str(str2time(m, "%m"), "%B");
  21. printf{0..0: m < t+2} " ";
  22. }
  23. printf "\n";
  24. for {m in t..t+2}
  25. { printf " S M Tu W Th F S";
  26. printf{0..0: m < t+2} " ";
  27. }
  28. printf "\n";
  29. for {k in 0..5}
  30. { for {m in t..t+2}
  31. { for {d in 0..6}
  32. { printf{0..0: cal[m,k,d] = 0} " ";
  33. printf{0..0: cal[m,k,d] != 0} " %2d", cal[m,k,d];
  34. }
  35. printf{0..0: m < t+2} " ";
  36. }
  37. printf "\n";
  38. }
  39. }
  40. printf "\n";
  41. end;