Documentation
¶
Overview ¶
Example ¶
package main import ( "fmt" "sort" "github.com/iand/gdate" ) func main() { input := []string{ "7 Nov 1880", "5 Nov 1878", "6 Apr 1877", "before 1877", "not a date", "after 1878", "1885", "about 1879", } dates := []gdate.Date{} for _, in := range input { dt, _ := gdate.Parse(in) dates = append(dates, dt) } sort.Slice(dates, func(i, j int) bool { return gdate.SortsBefore(dates[i], dates[j]) }) fmt.Println("sorted dates") for _, dt := range dates { fmt.Printf(" - %s\n", dt.String()) } }
Output: sorted dates - bef. 1877 - 6 Apr 1877 - 5 Nov 1878 - aft. 1878 - abt. 1879 - 7 Nov 1880 - 1885 - not a date
Index ¶
- func IsUnknown(d Date) bool
- func IsUnknownInterval(in Interval) bool
- func SortsBefore(a, b Date) bool
- type AboutYear
- type AboutYearsInterval
- type AfterYear
- type BeforeYear
- type Calendar
- type ComparableDate
- type Date
- type EstimatedYear
- type Interval
- type MonthYear
- type Parser
- type Precise
- type PreciseInterval
- type ReckoningLocation
- type Unknown
- type UnknownInterval
- type Year
- type YearQuarter
- type YearRange
- type YearsInterval
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsUnknownInterval ¶
IsUnknownInterval reports whether in is an unknown interval
func SortsBefore ¶
SortsBefore reports whether a should sort before b chronologically
Types ¶
type AboutYear ¶
AboutYear represents a date that is near to a specific year
func (*AboutYear) Occurrence ¶
func (*AboutYear) SortsBefore ¶
type AboutYearsInterval ¶
type AboutYearsInterval struct {
Y int
}
func (*AboutYearsInterval) Precise ¶
func (i *AboutYearsInterval) Precise() string
func (*AboutYearsInterval) Rough ¶
func (i *AboutYearsInterval) Rough() string
func (*AboutYearsInterval) Years ¶
func (p *AboutYearsInterval) Years() int
type AfterYear ¶
AfterYear represents a date that is after the end of a specific year
func (*AfterYear) Occurrence ¶
func (*AfterYear) SortsBefore ¶
type BeforeYear ¶
BeforeYear represents a date that is before the start of a specific year. It sorts before any date with that year.
func (*BeforeYear) Calendar ¶ added in v0.1.1
func (b *BeforeYear) Calendar() Calendar
func (*BeforeYear) Occurrence ¶
func (b *BeforeYear) Occurrence() string
func (*BeforeYear) SortsBefore ¶
func (b *BeforeYear) SortsBefore(d Date) bool
func (*BeforeYear) String ¶
func (b *BeforeYear) String() string
type Calendar ¶ added in v0.1.1
type Calendar int
type ComparableDate ¶ added in v0.1.1
type EstimatedYear ¶
EstimatedYear represents a date that is estimated to be a specific year
func (*EstimatedYear) Calendar ¶ added in v0.1.1
func (e *EstimatedYear) Calendar() Calendar
func (*EstimatedYear) Occurrence ¶
func (e *EstimatedYear) Occurrence() string
func (*EstimatedYear) SortsBefore ¶
func (e *EstimatedYear) SortsBefore(d Date) bool
func (*EstimatedYear) String ¶
func (e *EstimatedYear) String() string
func (*EstimatedYear) Year ¶
func (e *EstimatedYear) Year() int
type Interval ¶
func IntervalBetween ¶
type MonthYear ¶
Year is a date for which only the month and year is known or a period of time that may span an entire month. It sorts before any date with a higher numeric year.
func (*MonthYear) EarliestJulianDay ¶ added in v0.1.1
func (*MonthYear) LatestJulianDay ¶ added in v0.1.1
func (*MonthYear) Occurrence ¶
type Parser ¶
type Parser struct { // ReckoningLocation specifies the location from which the date originated and is used // to set the calendar based on the year of calendar change in that location. To force // a known calendar to be used, set this to ReckoningLocationNone and set the Calendar // field to the required calendar. ReckoningLocation ReckoningLocation // AssumeGROQuarter controls whether the parse will assume that ambiguous dates consisting of a month and a year, // where the month is the start or end of a quarter, refer to the UK General Register Office quarter // containing that month, so July 1850 will be parsed as 3rd Quarter, 1850 AssumeGROQuarter bool // Calendar specifies the calendar to use for the date if ReckoningLocation is set to ReckoningLocationNone. Calendar Calendar }
A Parser converts strings into dates
type Precise ¶
Precise is a date with a known year, month and day.
func AsPrecise ¶
AsPrecise returns the date as a precise date and true if possible, false if it is not possible to convert.
func (*Precise) DateInYear ¶
func (*Precise) EarliestJulianDay ¶ added in v0.1.1
func (*Precise) LatestJulianDay ¶ added in v0.1.1
func (*Precise) Occurrence ¶
type PreciseInterval ¶
type PreciseInterval struct {
Y, M, D int
}
func AsPreciseInterval ¶
func AsPreciseInterval(in Interval) (*PreciseInterval, bool)
AsPreciseInterval returns the interval as a PreciseInterval and true if possible, false if it is not possible to convert.
func (*PreciseInterval) ApproxDays ¶
func (p *PreciseInterval) ApproxDays() int
func (*PreciseInterval) Months ¶
func (p *PreciseInterval) Months() int
func (*PreciseInterval) Precise ¶
func (p *PreciseInterval) Precise() string
func (*PreciseInterval) Rough ¶
func (p *PreciseInterval) Rough() string
func (*PreciseInterval) Years ¶
func (p *PreciseInterval) Years() int
type ReckoningLocation ¶ added in v0.1.1
type ReckoningLocation int
The ReckoningLocation is the location used to determine the reckoning of the calendar which determines the date on which the first day of the year changed to 1 Jan and the date on which the calendar changed from Julian to Gregorian
const ( // TODO: non-English reckonings ReckoningLocationNone ReckoningLocation = 0 EnglandAndWales ReckoningLocation = 1 Scotland ReckoningLocation = 2 Ireland ReckoningLocation = 3 )
func (ReckoningLocation) Calendar ¶ added in v0.1.1
func (r ReckoningLocation) Calendar(y int) Calendar
StartOfYear returns calendar in use for the year specified.
type Unknown ¶
Unknown is an unknown date. It sorts after every other type of date.
func (*Unknown) Occurrence ¶
func (*Unknown) SortsBefore ¶
type UnknownInterval ¶
type UnknownInterval struct{}
func (*UnknownInterval) Precise ¶
func (i *UnknownInterval) Precise() string
func (*UnknownInterval) Rough ¶
func (i *UnknownInterval) Rough() string
type Year ¶
Year is a date for which only the year is known or a period of time that may span an entire year. It sorts before any date with a higher numeric year.
func AsYear ¶
AsYear returns the date as a Year and true if possible, false if it is not possible to convert.
func (*Year) EarliestJulianDay ¶ added in v0.1.1
func (*Year) LatestJulianDay ¶ added in v0.1.1
func (*Year) Occurrence ¶
type YearQuarter ¶
YearQuarter represents quarter of a specific year, based on GRO quarters Values of Q correspond to quarters as follows: 1 = Jan-Mar, known as MAR QTR 2 = Apr-Jun, known as JUN QTR 3 = Jul-Sep, known as SEP QTR 4 = Oct-Dec, known as DEC QTR
func (*YearQuarter) Calendar ¶ added in v0.1.1
func (y *YearQuarter) Calendar() Calendar
func (*YearQuarter) EarliestJulianDay ¶ added in v0.1.1
func (y *YearQuarter) EarliestJulianDay() int
func (*YearQuarter) LatestJulianDay ¶ added in v0.1.1
func (y *YearQuarter) LatestJulianDay() int
func (*YearQuarter) MonthRange ¶
func (y *YearQuarter) MonthRange() string
func (*YearQuarter) Occurrence ¶
func (y *YearQuarter) Occurrence() string
func (*YearQuarter) String ¶
func (y *YearQuarter) String() string
func (*YearQuarter) Year ¶
func (y *YearQuarter) Year() int
type YearRange ¶ added in v0.1.1
type YearRange struct { C Calendar Lower int // first year of the range Upper int // last year of the range }
YearRange represents a date that is within the range of two years, including the upper and lower year.
func (*YearRange) EarliestJulianDay ¶ added in v0.1.1
func (*YearRange) LatestJulianDay ¶ added in v0.1.1
func (*YearRange) Occurrence ¶ added in v0.1.1
type YearsInterval ¶
type YearsInterval struct {
Y int
}
func AsYearsInterval ¶
func AsYearsInterval(in Interval) (*YearsInterval, bool)
AsYearsInterval returns the interval as a YearsInterval and true if possible, false if it is not possible to convert.
func (*YearsInterval) Precise ¶
func (i *YearsInterval) Precise() string
func (*YearsInterval) Rough ¶
func (i *YearsInterval) Rough() string
func (*YearsInterval) Years ¶
func (p *YearsInterval) Years() int