HuTime Web API (Calendar Calculation) provides functions to convert calendar and calculate periods based on a calendar. The API allows you to manipulate a variety of periods defined by the calendar, including not only a calendar date but also an era name, a calendar year, a calendar month or others (hereinafter, the “Calendar Period").
This chapter describes the items common to all processes for use of the Web API. For items unique to each process, refer to Details of Each Process.
Set a required value to each variable and submit a request by the POST or GET method to the following URL.
http://ap.hutime.org/cal/
(E.g.) Convert a calendar date on the Gregorian calendar into that on the Japanese calendar (the GET method).
http://ap.hutime.org/cal/?method=conv&ical=101.1&itype=date&ival=2017-11-16&ocal=1001.1
You can also use the API according to JSON-RPC 2.0. In this case, however, you can only use the POST method and need to set the content-type in the request header to "application/json".
(E.g.) Convert a calendar date on the Gregorian calendar into that on the Japanese calendar.
A Calendar Period as input data should be specified either by (1) specifying a calendar resource of the Linked Data about Calendars or (2) setting necessary information for each variable. Some processes require you to set values for iuri2, ical2, itype2, ical2, and iform2 variables, in addition to the following variables.
Set a calendar resource for the variable "iuri."
(E.g.) When specifying November 17, 2017, a calendar date on the Gregorian calendar (the same calendar date is specified in any of the following three cases):
Set a calendar and type of a Calendar Period, as well as a value or a character string that represents a Calendar Period for the following variables.
Specifier | Type of Calendar Period |
---|---|
date | Calendar date |
month | Calendar month |
year | Calendar year |
era | Era name |
10y 100y 1000y | Periods of years (Indicate 10, 100 and 1000 years, respectively.) |
century millennium | Century and millennium (Only available in a calendar derived from the Gregorian or Julian calendar.) |
(E.g.) When specifying November 17, 2017, a calendar date on the Gregorian calendar:
You can enter multiple Calendar Periods and process them in bulk. For specification by calendar resource, separate URIs by line breaks (CRLF) and set them in "iuri". For specification by variable, separate values that are set in "ival" by line breaks. For specification by calendar resource, each URI contains the information about calendar and type. For specification by variable, however, only one value can be set for each of "ical" and "itype". Therefore, specification by calendar resource allows you to specify multiple Calendar Period of different calendars and types, whereas specification by variable limits you to the calendar and type that are set in "ical" and "itype".
(E.g.) Specify months of March 2016, April 2016 and May 2016. "\r\n" indicates a line break.
As for information on Calendar Periods, set the following specifiers in the variable "oprop". If this setting is omitted, the API outputs a character string that represents a Calendar Period. You can also obtain multiple items by separating specifiers with ";". In this case, the output formats "text" or "tsv" deliver the multiple items in the tab-delimited style, while the "csv" format delivers them in the comma-delimited style. When the output format is "json", values are stored in the variables whose specifiers are variable names.
Classification | Specifier | Type | Output |
---|---|---|---|
Period text | text val | Character string | A character string that represents a Calendar Period (default value) (The variable "oform" can be used to specify a format.) |
Time range | begin | Calendar Period | A Calendar Period that indicates the beginning point of a period |
end | Calendar Period | A Calendar Period that indicates the end point of a period | |
jdBegin | Numerical value | A Julian Date that indicates the beginning point of a range | |
jdEnd | Numerical value | A Julian Date that indicates the end point of a range | |
Sequence | previous | Calendar Period | Previous Calendar Period |
next | Calendar Period | Next Calendar Period | |
Hierarchical relationship | ofEra | Calendar Period | A name of an era to which the date belongs |
ofYear | Calendar Period | A calendar year to which the date belongs | |
ofMonth | Calendar Period | A calendar month to which the date belongs | |
Calendar resource | uri url iri | Character string | Calendar resource URI |
label | Character string | Calendar resource label | |
Others | dayDuration | Numerical value | Duration of a period (no. of days) |
calendarDuration | Character string | Duration of a period (+ no. of years - no. of months - no. of days) | |
isLeap | Boolean | Whether a Calendar Period is leap or not |
When a type of an item to be output is a Calendar Period, the output can be recursively assigned to another output item. For example, the specifier "next" of a calendar date (i.e. next day) is naturally a calendar date, which means that the calendar date can be assigned an output item to output a "calendar resource URI for the next day." In this case, use "." to connect specifiers as "next.uri". "next.next.uri" can output a "calendar resource URI for the day after 2 days." The number of specifiers that can be connected is limited to 3 in order to reduce the server load.
As for the output format, set the following specifiers in the variable "out". The character code of the output data is UTF-8.
Classification | Specifier | Output |
---|---|---|
Text | text |
Raw text (default value) Delimited by line breaks (CRLF) for every input data (Calendar Period). Delimited by tabs as tsv if multiple output items are specified, except that it has no title row. |
csv | Comma-delimited text file (CSV file) Generates a record for each input data (Calendar Period). The first row is a title row. |
|
tsv | Tab-delimited text file (TSV file) Generates a record for each input data (Calendar Period). The first row is a title row. |
|
json | JSON data file Generates an object for each input data (Calendar Period) and returns it as an array. Each object has a variable whose name is the specifier of the output item, each of which stores a value. |
|
RDF | rdf | Varies depending on the content-type of each request. application/json: RDF data file in the JSON format (rdf/json) Others: RDF data file in the XML format (rdf/xml) |
rdf/xml | RDF data file in the XML format | |
rdf/turtle | RDF data file in the turtle format | |
rdf/json | RDF data file in the JSON format | |
rdf/ntriple | RDF data file in the N3 format |
If the setting of the output format is omitted, the following applies depending on the setting value of the "content-type" in the request header:
If a process fails to be completed due to a problem with input data or other reasons, the API returns error details with HTTP status codes as shown below. JSON-RPC returns all errors as successful HTTP responses (HTTP status code: 200) and the error details are returned in the JSON format according to the JSON-RPC rules.
Status Code | Error Details |
---|---|
401 | A mandatory variable is not set or a value is invalid. |
404 | No corresponding Calendar Period is found (invalid specification). |
413 | The body length exceeds the limit during access by POST method. |
Based on the setting of the variable "oprop," obtain information such as a character string (period text) that represents a Calendar Period, duration, sequence, hierarchical relationship, and leap.
Details of the items specified in the variable "oprop".
"ival" has a character string representing three calendar months separated by line breaks, and they are processed in bulk. The format of the character strings to be output is set in the variable "oform" and the three calendar months, which are expressed in different formats, are integrated into a single format.
method = info ical = 101.1 itype = month ival = 2016 Mar\r\n2016 April\r\n2016-5 oform = yyyy-MM
2016-03\r\n2016-04\r\n2016-05
Convert a Calendar Period into that on a different calendar.
ep Setting Value | Points Used as Conversion Standard |
---|---|
b | Beginning point (default value) |
e | Ending point |
be eb | Beginning point and ending point Both results are separated by a line break (CRLF) and returned. Output order differs between "be" and "eb". |
Details of the items specified in the variable "oprop" for a converted Calendar Period.
Obtain Gregorian calendar years that correspond to the Genroku (元禄) era in Japanese Calendar. As both of the beginning point and the ending point are specified as reference points ofthe conversion (variable "ep"), the two Gregorian calendar years that correspond to the points are output separated by a line break.
method = conv ep = be iuri = http://datetime.hutime.org/calendar/1001.1/era/元禄 ocal = 101.1 otype = year
C.E. 1688\r\nC.E. 1704
Add a duration to a Calendar Period to obtain a resultant Calendar Period, such as "1 month and 15 days after March 2nd, 2016." Multiple values for either base points or added durations can be specified. If multiple values are specified for each, those durations are added to the first Calendar Period of the base points.
ep Setting Value | Points Used as Conversion Standard |
---|---|
bb | Beginning point of a base point to the beginning point of a target point (default value) |
ee | Ending point of a base point to the ending point of a target point |
be | Beginning point of a base point to the ending point of a target point |
eb | Ending point of a base point to the beginning point of a target point |
Details of the items specified in the variable "oprop" for the Calendar Period to which a duration is added.
Obtain date 1 month and 15 days after March 2nd, 2016. The duration to be added is based on the Julian-Gregorian calendar (variable "ical2"). fifteen days is represented as "+0-1-15" in the order of years, months, and days (variable "ival2").
method = addCal ep = bb ical = 101.1 itype = date ival = 2016-03-02 ical2 = 101.1 ival2 = +0-1-15
C.E. 2016 April 17
Obtain duration between two Calendar Periods (from the base point to the target point). One such example is how many years, months and days there were between March 14th, 1879 and 18th April, 1955. You can specify multiple base points or target points. If multiple values are specified for each, the duration between the first base point and each of the target points is calculated.
ep Setting | Points Used for Measurement |
---|---|
bb | Beginning point of a base point to the beginning point of a target point (default value) |
ee | Ending point of a base point to the ending point of a target point |
be | Beginning point of a base point to the ending point of a target point |
eb | Ending point of a base point to the beginning point of a target point |
odur Setting | Type Used to Express a Period |
---|---|
ymd | ±[No. of years]-[No. of months]-[No. of days] (default value) |
md | ±0-[No. of months]-[No. of days] |
yd | ±[No. of years]-0-[No. of days] |
d | ±0-0-[No. of days] |
A duration between a base point and a target point. When expressing a duration by days (method = "durDays"), its numerical value is returned. When expressing it by years, months and days (method = "durCal"), a character string representing the period is returned according to the "odur" setting. The sign becomes negative when the calculation’s target point comes before the base point.
Calculate the life span of Albert Einstein (from March 14th, 1879 to 18th April, 1955). The outcome turns out to be 76 years and 1 months and 5 days. Beginning and ending points are specified in order to calculate the period of his life span.
method = durCal ep = be ical = 101.1 itype = date ival = 1879-03-14 ical2 = 101.1 itype2 = date ival2 = 1955-04-18
+76-1-5
Obtain a relative relation between two Calendar Periods on the temporal axis based on Allen's Time Interval Algebra. You can enter multiple Calendar Periods for either A or B in the following figure. If multiple Calendar Periods are entered for both, each Calendar Period for B is compared with the first Calendar Period for A.
Allen's Time Interval Algebra (Allen 1983)
A relative relation between two Calendar Periods on the temporal axis. The result is returned based on Allen’s Time Interval Algebra.
Obtain a relative relation between the Genroku (元禄) era (1688-1704) on the Japanese calendar and the 17th century on the Gregorian calendar. The result "OverlappedBy" indicates that the 17th century began earlier than the Genroku era, and after the two periods were overlapped, the Genroku era ended later than the 17th century.
method = comp ical = 1001.1 itype = era ival = 元禄 ical2 = 101.1 itype2 = century ival2 = 17
OverlappedBy