Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stdlib: Calendar library #466

Merged
merged 7 commits into from
Jan 4, 2020
Merged

Conversation

statementreply
Copy link
Contributor

@statementreply statementreply commented Jan 1, 2020

The numeric convention is tentative and open to discussion. It is somewhat arbitrary.

  • month() is 1-12 for regular months, (N + 0.5) for leap month
  • day() is 1-30
  • largeHour() is 1-12 (子, 丑, ... 亥)
  • smallHour() is 0-23 (子正, 丑初, 丑正, ... 亥初, 亥正, 子初)
  • quarter() is 0-3 (4 reserved for old system)
  • minute() and second() are 0-59 (60-99 reserved for old system)
  • sexagenarianYear() and sexagenarianDay() are 1-60, 1 = 甲子
  • Total year (60 N + 1) is 甲子 year
  • Total day (60 N + 1) is 甲子 day
  • Total year is close to the convention(s) used by some overseas Chinese communities
  • Total day 0 is close to the beginning of total year 0 and total month 0 if we apply the current calendar rules backwards in time.

For example, under the tentative convention, 2020-01-25 05:42:00 庚子年正月初一日卯初二刻一十二分 would be:

Function Value
彼年何年 2020
彼年何干支 37
彼年積何年 4717
彼月何月 1
彼月積何月 58341
彼日何日 1
彼日何干支 4
彼日積何日 1722844
彼時何時 4
彼時何小時 5
彼刻何刻 2
彼分何分 12
彼秒何秒 0

@LingDong-
Copy link
Member

Looking forward to it! 👍

The implementation is LUT based. This commit contains LUT for years
2019-2020 for dev purpose.
The calendar data is generated with low accuracy astronomical
computation of the time of new moons and solar terms. Due to the low
accuracy and/or uncertainty of future leap seconds, calendar near the
following days might be off by one day or one month.

1722401 (2018-11-08): maybe wrong 1st day of month (new moon at 1722401.0023)
1736606 (2057-09-29): maybe wrong 1st day of month (new moon at 1736606.0011)
1748269 (2089-09-04): maybe wrong 1st day of month (new moon at 1748270.0003)
1751164 (2097-08-08): maybe wrong 1st day of month (new moon at 1751164.0019)
1757572 (2115-02-24): maybe wrong 1st day of month (new moon at 1757573.0000)
1758015 (2116-05-12): maybe wrong 1st day of month (new moon at 1758016.0002)
1687201 (1922-06-25): maybe wrong leap month (solar term at 1687230.010, new moon at 1687230.8663)
1709998 (1984-11-23): maybe wrong leap month (solar term at 1710027.015, new moon at 1710027.8248)
1710973 (1987-07-26): maybe wrong leap month (solar term at 1711002.009, new moon at 1711002.8329)
@statementreply statementreply changed the title [WIP] stdlib: Calendar library stdlib: Calendar library Jan 4, 2020
@statementreply
Copy link
Contributor Author

The calendar data is generated with low accuracy astronomical computation of the time of new moons and solar terms. Due to the low accuracy and/or uncertainty of future leap seconds, calendar near the following days might be off by one day or one month.

1722401 (2018-11-08): maybe wrong 1st day of month (new moon at 1722401.0023)
1736606 (2057-09-29): maybe wrong 1st day of month (new moon at 1736606.0011)
1748269 (2089-09-04): maybe wrong 1st day of month (new moon at 1748270.0003)
1751164 (2097-08-08): maybe wrong 1st day of month (new moon at 1751164.0019)
1757572 (2115-02-24): maybe wrong 1st day of month (new moon at 1757573.0000)
1758015 (2116-05-12): maybe wrong 1st day of month (new moon at 1758016.0002)
1687201 (1922-06-25): maybe wrong leap month (solar term at 1687230.010, new moon at 1687230.8663)
1709998 (1984-11-23): maybe wrong leap month (solar term at 1710027.015, new moon at 1710027.8248)
1710973 (1987-07-26): maybe wrong leap month (solar term at 1711002.009, new moon at 1711002.8329)

Computation methods used for generating the data:

  • Solar motion: formula from https://ssd.jpl.nasa.gov/?planet_pos
  • Lunar motion: ELP/MPP02 (There happens to be an implementation of it on my computer :D)
  • Light time and aberration correction: approximate formula
  • Other relativistic corrections: ignored
  • Precession: IERS conventions 2010
  • Nutation: only the largest 18.6-year-period term
  • Delta T: historical value before 2020, extrapolation for 2020-2028, fixed extrapolated 2028 value after 2028 (assume that leap seconds were to be abolished in 2028)

The resulting new moon time is accurate to ~1.5 minutes (uncertainty of delta T excluded), solar term time to ~20 minutes.

@statementreply statementreply marked this pull request as ready for review January 4, 2020 13:34
@LingDong- LingDong- merged commit 1a95dc2 into wenyan-lang:master Jan 4, 2020
@LingDong-
Copy link
Member

Awesome, thank you so very much! 👍

@antfu antfu mentioned this pull request Jan 5, 2020
@statementreply statementreply deleted the lib-calendar branch January 11, 2020 11:32
LingDong- added a commit that referenced this pull request Jan 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants