The algorithm for calculating the target year of the target month is 12 months * Calendar *

GOAL . The goal of this stream is to create a mathematical formula to replace the long-term solution with @lawlist in the lawlist-target-year-function (below).

NOTE The solution to this thread is somewhat similar, but it will still be different from the algorithm written by @AShelly in the linked thread: https://stackoverflow.com/a/166778/

PROBLEM OF HISTORY

Emacs now has a 12-month calendar that scrolls back and forth one month (or more) at a time. A helper function called lawlist-target-year-function is used by the sevaral holiday function to place an overlay on each holiday.

The full working draft of a 12-month scroll calendar (including a long-term solution) can be found here - [the source code of Github has been changed to include a concise algorithmic solution @legoscia]:

https://github.com/lawlist/calendar-yearly-scroll-by-month/blob/master/lawlist-cal.el

LEGEND

displayed-month (numbers 1 to 12) is the month that appears in the upper left corner of the buffer, and this changes when the 12-month calendar scrolls forward or backward.

target-month (numbers 1 to 12) is the month that contains the holiday that will be marked by the overlay. There are three (3) possible x axis coordinates (i.e., Column 1, Column 2, or Column 3). There are four (4) possible y axis coordinates (i.e., Line 1, Line 2, Line 3, or Line 4). [Quote to x / y coordinates: http://www.mathsisfun.com/data/cartesian-coordinates.html ]

displayed-year is the year that is displayed in the upper left corner of the buffer, and this changes when the 12-month calendar scrolls forward or backward.

The target year is the target-month year.

An example :

  • When displayed-month is January (i.e. 1), then the year will be the same for all target months.

  • When displayed-month is February (i.e. 2):

     (if (memq target-month `(2 3 4 5 6 7 8 9 10 11 12)) displayed-year (+ displayed-year 1)) 
  • When displayed-month is March (i.e. 3):

     (if (memq target-month `(3 4 5 6 7 8 9 10 11 12)) displayed-year (+ displayed-year 1)) 
  • When displayed-month is April (i.e. 4):

     (if (memq target-month `(4 5 6 7 8 9 10 11 12)) displayed-year (+ displayed-year 1)) 
  • When displayed-month is May (i.e. 5)

     (if (memq target-month `(5 6 7 8 9 10 11 12)) displayed-year (+ displayed-year 1)) 
  • When displayed-month is June (i.e. 6):

     (if (memq target-month `(6 7 8 9 10 11 12)) displayed-year (+ displayed-year 1)) 
  • When displayed-month is July (i.e. 7):

     (if (memq target-month `(7 8 9 10 11 12)) displayed-year (+ displayed-year 1)) 
  • When displayed-month is August (i.e. 8):

     (if (memq target-month `(8 9 10 11 12)) displayed-year (+ displayed-year 1)) 
  • When displayed-month is September (i.e. 9):

     (if (memq target-month `(9 10 11 12)) displayed-year (+ displayed-year 1)) 
  • When displayed-month is October (i.e. 10):

     (if (memq target-month `(10 11 12)) displayed-year (+ displayed-year 1)) 
  • When displayed-month is November (i.e. 11):

     (if (memq target-month `(11 12)) displayed-year (+ displayed-year 1)) 
  • When displayed-month is December (i.e. 12):

     (if (memq target-month `(12)) displayed-year (+ displayed-year 1)) 

The 12-month calendar is as follows: the layout scrolls forward one month at a time:

 ;; 1 2 3 ;; 4 5 6 ;; 7 8 9 ;; 10 11 12 ;; 2 3 4 ;; 5 6 7 ;; 8 9 10 ;; 11 12 1 ;; 3 4 5 ;; 6 7 8 ;; 9 10 11 ;; 12 1 2 ;; 4 5 6 ;; 7 8 9 ;; 10 11 12 ;; 1 2 3 ;; 5 6 7 ;; 8 9 10 ;; 11 12 1 ;; 2 3 4 ;; 6 7 8 ;; 9 10 11 ;; 12 1 2 ;; 3 4 5 ;; 7 8 9 ;; 10 11 12 ;; 1 2 3 ;; 4 5 6 ;; 8 9 10 ;; 11 12 1 ;; 2 3 4 ;; 5 6 7 ;; 9 10 11 ;; 12 1 2 ;; 3 4 5 ;; 6 7 8 ;; 10 11 12 ;; 1 2 3 ;; 4 5 6 ;; 7 8 9 ;; 11 12 1 ;; 2 3 4 ;; 5 6 7 ;; 8 9 10 ;; 12 1 2 ;; 3 4 5 ;; 6 7 8 ;; 9 10 11 

@Lawlist's long-term solution is as follows:

 (defun lawlist-target-year-function (target-month) (cond ;; 1 2 3 ;; 4 5 6 ;; 7 8 9 ;; 10 11 12 ((eq displayed-month 1) displayed-year) ;; 2 3 4 ;; 5 6 7 ;; 8 9 10 ;; 11 12 1 ((eq displayed-month 2) (if (memq target-month `(2 3 4 5 6 7 8 9 10 11 12)) displayed-year (+ displayed-year 1))) ;; 3 4 5 ;; 6 7 8 ;; 9 10 11 ;; 12 1 2 ((eq displayed-month 3) (if (memq target-month `(3 4 5 6 7 8 9 10 11 12)) displayed-year (+ displayed-year 1))) ;; 4 5 6 ;; 7 8 9 ;; 10 11 12 ;; 1 2 3 ((eq displayed-month 4) (if (memq target-month `(4 5 6 7 8 9 10 11 12)) displayed-year (+ displayed-year 1))) ;; 5 6 7 ;; 8 9 10 ;; 11 12 1 ;; 2 3 4 ((eq displayed-month 5) (if (memq target-month `(5 6 7 8 9 10 11 12)) displayed-year (+ displayed-year 1))) ;; 6 7 8 ;; 9 10 11 ;; 12 1 2 ;; 3 4 5 ((eq displayed-month 6) (if (memq target-month `(6 7 8 9 10 11 12)) displayed-year (+ displayed-year 1))) ;; 7 8 9 ;; 10 11 12 ;; 1 2 3 ;; 4 5 6 ((eq displayed-month 7) (if (memq target-month `(7 8 9 10 11 12)) displayed-year (+ displayed-year 1))) ;; 8 9 10 ;; 11 12 1 ;; 2 3 4 ;; 5 6 7 ((eq displayed-month 8) (if (memq target-month `(8 9 10 11 12)) displayed-year (+ displayed-year 1))) ;; 9 10 11 ;; 12 1 2 ;; 3 4 5 ;; 6 7 8 ((eq displayed-month 9) (if (memq target-month `(9 10 11 12)) displayed-year (+ displayed-year 1))) ;; 10 11 12 ;; 1 2 3 ;; 4 5 6 ;; 7 8 9 ((eq displayed-month 10) (if (memq target-month `(10 11 12)) displayed-year (+ displayed-year 1))) ;; 11 12 1 ;; 2 3 4 ;; 5 6 7 ;; 8 9 10 ((eq displayed-month 11) (if (memq target-month `(11 12)) displayed-year (+ displayed-year 1))) ;; 12 1 2 ;; 3 4 5 ;; 6 7 8 ;; 9 10 11 ((eq displayed-month 12) (if (memq target-month `(12)) displayed-year (+ displayed-year 1))) )) 
0
source share
1 answer

Will this work?

 (defun lawlist-target-year-function (target-month) (if (>= target-month displayed-month) displayed-year (1+ displayed-year))) 
+2
source

All Articles