This document defines date and time formats and algorithms.
This specification depends on the Infra Standard.
The term ASCII digit is defined by the Infra Standard.
The term utf-8 is defined by the Encoding Standard.
The JD day number of a day is a Julian Day number representing the start of the day in UTC.
Unlike the Julian Day Number (JDN), the JD day number is not an integer.
An AD year is an integer.
Note that the year just before year 1 is year 0, not year −1.
A string is a year string representing an AD year year, if it consists of the following components in the given order:
U+002D
HYPHEN-MINUS
character
(-
)
To parse a year string string, the implementation MUST run these steps:
U+002B
PLUS SIGN
character (+
), remove it from input.
U+002D
HYPHEN-MINUS
character
(-
), remove it from input
and set sign to −1.
A string is a YMD string of a tuple (year, month, day) if it consists of the following components in the given order:
U+002D
HYPHEN-MINUS
character
(-
)
U+002D
HYPHEN-MINUS
character
(-
)
To parse a YMD string string, the implementation MUST run these steps:
U+002B
PLUS SIGN
character (+
), remove it from input.
U+002D
HYPHEN-MINUS
character
(-
), remove it from input
and set sign to −1.
U+002D
HYPHEN-MINUS
character
(-
), followed by one or
more ASCII digits, followed by
a U+002D
HYPHEN-MINUS
character
(-
), followed by one or
more ASCII digits, return
(failure, failure, failure) and abort these
steps.
The notation era.prop
,
where era is an era, represents that the value of the
name/value pair whose name is prop of the era description
(a JSON object contained as a value of the eras
value of
the topmost object) in the calendar-era-defs data file.
The era key of an era era is
era.key
. An era key is a short
string which uniquely identifies an era.
To convert from era era and year era year into an AD year, the implementation MUST run these steps:
era.offset
is null, return null.
era.offset
+ era
year.
If the mapping from era to AD is not known, these steps return null.
To convert an AD year year for era era into a year era year in era, the implementation MUST run these steps:
era.offset
is null, return null.
era.offset
.
If the mapping from AD to era is not known, these steps return null.
A string is an era year string representing a year year in era era, if it consists of the following components in the given order:
U+002D
HYPHEN-MINUS
character
(-
)
A string is an era YMD string of a tuple (year, month, day) with era era if it consists of the following components in the given order:
U+002D
HYPHEN-MINUS
character
(-
)
U+002D
HYPHEN-MINUS
character
(-
)
An era name context is a mapping from strings to era keys, which is used to interpret era names in human-readable texts.
Era name contexts are defined
in the calendar-era-defs data file as values of
the name_to_key
JSON object in the topmost object.
To get an era from name name in era name context context, the implementation must run these steps:
An era name context is required to interpret strings as eras as there are different eras sharing the same name.
An era system is a set of rules to choose an era which is appropriate for a day.
An era system has an ordered sequence of time points. A time point is a tuple of type, value, and era. The type is one of Julian Day and year. If the type is Julian Day, the value is the JD day number of a day. If the type is year, the value is an AD year.
To get the era and era year of a calendar day day using an era system eras, the implementation MUST run these steps:
These steps return a pair of an era and a year in the era, which can be used to represent day. If no era is defined by eras for day, it returns nothing.
For the purpose of this specification, a calendar day is a Gregorian calendar day, Julian calendar day, or Kyuureki day.
For the purpose of this specification, the Gregorian calendar refers to the proleptic Gregorian calendar.
A Gregorian calendar day represents a day in the Gregorian calendar. It is identified by a tuple of an AD year, a month number, and a day number. The year number is an integer. The month number is an integer in the range [1, 12]. The day number is an integer in the range [1, 31].
Not all months have the days 29, 30, and 31.
A string is a Gregorian date string of a Gregorian calendar day (year, month, day) if it is a YMD string of the tuple (year, month, day).
If it represents a valid day and year is in the range [1, 9999], it is also a valid date string.
A string is a Gregorian era date string of a Gregorian calendar day (year, month, day) with era era if it is an era YMD string of the tuple (year, month, day) in era.
To get a Gregorian date from a year string string, the implementation must run these steps:
To get a Gregorian date from a YMD string string, the implementation must run these steps:
For the purpose of this specification, the Julian calendar refers to the proleptic Julian calendar.
A Julian calendar day represents a day in the Julian calendar. It is identified by a tuple of an AD year, a month number, and a day number. The year number is an integer. The month number is an integer in the range [1, 12]. The day number is an integer in the range [1, 31].
Not all months have the days 29, 30, and 31.
Julian calendar day is different from Julian Day.
A string is a Julian date string of a Julian calendar day (year, month, day) if it is a YMD string of the tuple (year, month, day).
A string is a Julian era date string of a Julian calendar day (year, month, day) with era era if it is an era YMD string of the tuple (year, month, day) in era.
The Kyuureki (旧暦) is the calendar system historically used in Japan. It is a variant of Chinese calendar systems.
It is normatively defined by 太陽暦 (Government of Japan, 1873-1879), 暦 (Government of Japan, 1880-1909), 日本百科大辭典 (keyword "太陰暦", 平山清次, 1912), 神宮暦 (神宮司廳, 1947-), 日本暦日原典 (内田正男, 1992), and 日本書紀暦日原典 (内田正男, 1993).
See also SuikaWiki:旧暦.
A Kyuureki day represents a day in the Kyuureki. It is identified by a tuple of an AD year, a month number, a boolean flag, and a day number. The year number is an integer. The month number is an integer in the range [1, 12], where the value 1 represents the 正月. If the boolean flag is true, the month is a leap month. Otherwise, it is not a leap month. The day number is an integer in the range [1, 30], where the value 1 represents the 朔日 of the month.
Not all months have the day 30.
A string is a Kyuureki date string of a Kyuureki day (year, month, is leap month, day) if it consists of the following components in the given order:
U+002D
HYPHEN-MINUS
character
(-
)
U+0027
APOSTROPHE
character
('
)
U+002D
HYPHEN-MINUS
character
(-
)
A string is a Kyuureki era date string of a Kyuureki day (year, month, is leap month, day) with era era if it consists of the following components in the given order:
U+002D
HYPHEN-MINUS
character
(-
)
U+0027
APOSTROPHE
character
('
)
U+002D
HYPHEN-MINUS
character
(-
)
A date mapping file is a file consist of zero of lines.
A line consists of two slots separated by a 0x09
byte,
followed by a 0x0A
byte. A line represents an entry in
the mapping, where the first slot represents the source of the entry
and the second slot represents the destination of the entry. The
values in the slots are encoded by utf-8.
The calendar-era-defs data file (documentation) is normatively referenced from this specification.
To resolve a day-of-time time-of-day daytime relative to a time with time-zone offset reference time, run these steps:
These steps return the time represented by daytime that is nearest to reference time.
Need to define time with time-zone offset, time-of-day, and time computations.
This section is non-normative.
There are tests for some parts of this specification.
This document is written by Wakaba <wakaba@suikawiki.org>.
This document is developed as part of the manakai project.
Per CC0, to the extent possible under law, the author has waived all copyright and related or neighboring rights to this work.