计算目标月 - 12个月目标年的算法*日历* [英] Algorithm to calculate the target-year of the target-month -- 12 month *Calendar*
问题描述
目标:此线程的目标是创建一个数学公式来替换@lawlist中的长方法,函数 lawlist-target-year-function
(以下)。
注意:这个线程的解决方案有些类似,但是会有所不同, @AShelly在相关线程中编写的算法: https://stackoverflow.com/a/21709710/2112489
故障问题
现在,Emacs中存在一个12个月的日历,向前滚动一次(或更多)一次。一个名为 lawlist-target-year-function
的帮助函数由sevaral假日函数用于在每个假日上放置重叠。
可以在这里找到12个月滚动日历(包括长期解决方案)的完整工作草案 - [Github源代码已被修改包括@legoscia的简洁算法解决方案]:
https://github.com/lawlist/calendar-yearly-scroll-by-month/blob/master/lawlist-cal.el
LEGEND :
/ code>(数字1到12)是出现在缓冲区左上角的月份,并且随着12个月的日历向前或向后滚动而改变。
目标月份
(数字1到12)是月份包含将标有叠加层的假期。有三(3)个可能的 x
轴坐标(即列1,列2或列3)。有四(4)个可能的 y
轴坐标(即行1,行2,行3或行4)。 [引用x / y坐标: http://www.mathsisfun.com/data/ cartesian-coordinates.html ]
显示年份
是出现在上层的年份缓冲区的左上角,随着12个月的日历向前或向后滚动,这一变化。
目标年份
是目标月份
的年份。
示例:
-
当
显示月份
是1月(即1)那么所有目标月份的年份是一样的。 -
当
显示月份
是二月,2):(if(memq target-month`(2 3 4 5 6 7 8 9 10 11 12))
显示年
(+显示年1))
-
当
显示月份
是3月(即3):(if(memq ta rget-month`(3 4 5 6 7 8 9 10 11 12))
显示年
(+显示年1))
-
当
显示月份
是四月(即4)时:(if(memq target-month`(4 5 6 7 8 9 10 11 12))
显示年
(+显示年份1))
-
当
显示月份
是May(即5)
(if(memq target-month`(5 6 7 8 9 10 11 12))
显示年
(+显示年1))
-
当
显示月份
是6月(即6):code>(if(memq target-month`(6 7 8 9 10 11 12))
显示年
(+显示年1))
-
当
显示月份
是七月(即7) / p>
(if(memq target-month`(7 8 9 10 11 12))
显示年
(+显示年份1))
-
当
莫第n个
是八月(即8):(if(memq target-month` 9 10 11 12))
显示年
(+显示年1))
-
当
显示月份
为9月(即9日)时:(if(memq target-month`(9 10 11 12))
显示年
(+显示年份1))
-
当
显示月份
是十月(即10)时:(if(memq target-month`(10 11 12))
显示年
(+年份1))
-
当
显示月份
是11月(即11):(if(memq target-month`(11 12))
显示年
(+显示年1))
-
显示月份
是十二月(即12):(if (memq target-month`(12))
显示年
(+显示年1))
12个月的日历如下所示:布局一次滚动一个月:
;; 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的长手解决方案如下:
(defun lawlist-target-year-function(target-month)
(cond
;; 1 2 3
;; 4 5 6
;; 7 8 9
;; 10 11 12
((eq显示月1)
显示年)
;; 2 3 4
;; 5 6 7
;; 8 9 10
;; 11 12 1
((eq显示月份2)
(if(memq目标月份(2 3 4 5 6 7 8 9 10 11 12))
显示年
(+显示年1))
;; 3 4 5
(6)()()(7)()()() 4 5 6 7 8 9 10 11 12))
显示年
(+显示年1))
;; 4 5 6
;; 7 8 9
;; 10 11 12
;; 1 2 3
((eq显示月份4)
(if(memq target-month`(4 5 6 7 8 9 10 11 12))
显示年
(+显示年1)))
;; 5 6 7
;; 8 9 10
;; 11 12 1
;; 2 3 4
((eq显示月份5)
(if(memq target-month`(5 6 7 8 9 10 11 12))
显示年
+显示年份1)))
;; 6 7 8
;; 9 10 11
;; 12 1 2
;; 3 4 5
((eq显示月份6)
(if(memq target-month`(6 7 8 9 10 11 12))
显示年
(+显示年份1)))
;; 7 8 9
;; 10 11 12
;; 1 2 3
;; 4 5 6
((eq显示月份7)
(if(memq target-month`(7 8 9 10 11 12))
显示年
(+显示-year 1)))
;; 8 9 10
;; 11 12 1
;; 2 3 4
;; 5 6 7
((eq显示月份8)
(if(memq target-month`(8 9 10 11 12))
显示年
(+年1)))
;; 9 10 11
;; 12 1 2
;; 3 4 5
;; 6 7 8
((eq显示月份9)
(if(memq target-month`(9 10 11 12))
显示年
(+显示年份1)))
;; 10 11 12
;; 1 2 3
;; 4 5 6
;; 7 8 9
((eq显示月份10)
(if(memq target-month`(10 11 12))
显示年
(+显示年1 )))
;; 11 12 1
;; 2 3 4
;; 5 6 7
;;新评新新新新新新新旗新新新新旗新新新新旗新新新新旗新新旗200新新新新旗新新旗200新新新新旗新新旗200新新新新新新旗新新旗200新新新新旗新新旗200新新新新旗新新旗200新新新新200新新新新旗新新旗新新旗旗))
;; 12 1 2
;; 3 4 5
;; 6 7 8
;;新评新新新新新新旗新新新新旗新新新新旗新新旗200新新新新新新旗新新旗200新新新新旗新新旗200新新新新旗新新旗200新新新新新旗200新新新新新旗200 Chan X- ))
(defun lawlist-target-year-function(target-month)
(if(> = target-month shows-month新评新新新旗新新新新旗新新新新旗新新旗新新旗新新旗旗新p新新新新新旗新新旗新新旗新新旗旗醒新年200新新新新旗新新旗旗醒新年200旗新新旗旗时旗新新新新旗新StrEC新新新旗200 200 200新新新新旗新StrEC新新新旗200新新新新旗200 200新新Version 200新新新新新旗新StrippEColGOAL: The goal of this thread is to create a mathematical formula to replace the long-hand solution by @lawlist in the function lawlist-target-year-function
(below).
NOTE: The solution to this thread is somewhat similar, but will nevertheless be different, than the algorithm written by @AShelly in a related thread: https://stackoverflow.com/a/21709710/2112489
STORY PROBLEM
There now exists a 12-month calendar in Emacs that scrolls forwards and backwards one month (or more) at a time. A helper function called lawlist-target-year-function
is used by sevaral holiday functions to place an overlay on each holiday.
A full working draft of the 12-month scrolling calendar (including the long-hand solution) may be found here -- [the Github source code has been revised to include the concise algorithm solution by @legoscia]:
https://github.com/lawlist/calendar-yearly-scroll-by-month/blob/master/lawlist-cal.el
LEGEND:
displayed-month
(numbers 1 through 12) is the month that appears in the upper left-hand corner of the buffer, and this changes as the 12-month calendar is scrolled forwards or backwards.
The target-month
(numbers 1 through 12) is the month that contains the holiday that will be marked with an 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., row 1, row 2, row 3, or row 4). [Citation to x / y coordinates: http://www.mathsisfun.com/data/cartesian-coordinates.html ]
The displayed-year
is the year that appears in the upper left-hand corner of the buffer, and this changes as the 12-month calendar is scrolled forwards or backwards.
The target year
is the year of the target-month
.
EXAMPLE:
When displayed-month
is January (i.e., 1), then the year is 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 looks like the following as 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
The long-hand solution by @lawlist 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))) ))
解决方案 Would this work?
(defun lawlist-target-year-function (target-month)
(if (>= target-month displayed-month)
displayed-year
(1+ displayed-year)))
这篇关于计算目标月 - 12个月目标年的算法*日历*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!