Documentation ¶
Index ¶
Constants ¶
const ErrNotDate = domain.Error("Value is not a date")
ErrNotDate is used to communicate that a value is not able to be parsed as a date
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Historic ¶
type Historic struct { Year int `json:"year"` Month int `json:"month,omitempty"` Day int `json:"day,omitempty"` IsBCE bool `json:"isBCE"` }
Historic represents a specific date from history. It stores the year, month, day and if whether or not the underlying date was BCE. Both month and day are optional, because some dates in history do not have that level of precision
func New ¶
New attempts to create a Historic date from its input string. At the moment this string has to be in YYYY-MM-DD [BC] format. For example, the following string dates are all valid inputs for this function: "1769-08-15", "1769-8-15", "1769-8", "1769" and "1457-04-16 BC"
func Parse ¶
Parse receives text containing a potential date or range of dates, and translates them into a slice of Historic, where the first element is the earliest date detected in the text, and the second element is the latest date detected in the text. If there is just one date detected, then the slice will just have one element
func (Historic) IsValid ¶
IsValid applies the IsValid algorithm to check if the underlying date is valid or not
func (Historic) ToBeginning ¶
ToBeginning fills the missing month and day of a partial Historic by setting them to 1 if they are missing. For example, the underlying date "1769" is converted into "1769-01-01", "1769-08" is converted into "1769-08-01", and "1769-08-15" stays the same
func (Historic) ToEnd ¶
ToEnd fills the missing month and day of a partial Historic by setting them to the last month of the year (unless specified), and to the last day of that month (unless specified). For example, the underlying date "1769" is converted into "1769-12-31", "1769-08" is converted into "1769-08-31", and "1769-08-15" stays the same
func (Historic) ToNum ¶
ToNum converts the Historic to a floating-point number, where the magnitude of the result will be directly proportional to how recent the underlying date was. For this purpose, if the Month or Day values of the Historic are zero, they will not be considered in this calculaiton. Following this logic, "1769-08-15" will be greater than "1769-08", which will in turn be greater than "1769". Whether or not the date is BCE is also considered, so "1769" will be greater than "1769 BC", in the same way that "31-09-02 BC" will be greater than "52-09 BC"