Using Calends in Golang
Calends exposes a very small handful of things for use outside the library
itself. One is the Calends class, documented here, which should be
the only interface users of the library ever need to touch.
Another thing Calends exposes is the calendars.TAI64NARUXTime class,
used to store and manipulate the instants of time which make up a
Calends instance. The rest are interfaces for extending the library’s
functionality. These are covered in the Custom Calendars in Golang section.
참고
Calends objects are immutable - all methods return a new
Calends object where they might otherwise alter the current one.
This is true even of the Calends.Set* methods. This has the side
effect of using more memory to perform manipulations than updating values on
an existing object would. It makes many operations safer, though, than
mutable objects would allow.
- Calends
The main entry point to Calends and its functionality.
Calendsobjects should only be created with theCreatefunction, and never directly (especially given its values are all unexported ones).
Create
- func Create(value interface, calendar string, format string) (Calends, error)
- 매개변수
value (
interface{}) – The value to parse the date(s)/time(s) from.calendar (
string) – The calendar system to parse the date(s)/time(s) with.format (
string) – The format the date(s)/time(s) is/are expected to use.
- 반환
A new
Calendsobject- 반환 형식
- 반환
errorwhen an error occurs;nilotherwise- 반환 형식
errorornil
Creates a new
Calendsobject, usingcalendarto select a calendar system, andformatto parse the contents ofvalueinto theCalendsobject’s internal instants. The type ofvaluecan vary based on the calendar system itself, but generally speaking can always be a string.In any case, the value can always be a
map[string]interface{}, where the keys are any two ofstart,end, andduration. If all three are provided,durationis ignored in favor of calculating it directly. If only one of the listed keys is provided,valueis passed to the calendar system itself unchanged.The calendar system then converts
valueto acalendars.TAI64NARUXTimeinstant, which theCalendsobject sets to the appropriate internal value.
Read
- func (Calends) Date(calendar string, format string) (string, error)
- 매개변수
calendar (
string) – The calendar system to format the date/time with.format (
string) – The format the date/time is expected to be in.
- 반환
The start date of the
Calendsobject- 반환 형식
string- 반환
errorwhen an error occurs;nilotherwise- 반환 형식
errorornil
Retrieves the start date of the
Calendsobject as a string. The value is generated by the calendar system given incalendar, according to the format string informat.
- func (Calends) EndDate(calendar string, format string) (string, error)
- 매개변수
calendar (
string) – The calendar system to format the date/time with.format (
string) – The format the date/time is expected to be in.
- 반환
The end date of the
Calendsobject- 반환 형식
string- 반환
errorwhen an error occurs;nilotherwise- 반환 형식
errorornil
Retrieves the end date of the
Calendsobject as a string. The value is generated by the calendar system given incalendar, according to the format string informat.
Update
- func (Calends) SetDate(stamp interface, calendar string, format string) (Calends, error)
- 매개변수
value (
interface{}) – The value to parse the date/time from.calendar (
string) – The calendar system to parse the date/time with.format (
string) – The format the date/time is expected to use.
- 반환
A new
Calendsobject- 반환 형식
- 반환
errorwhen an error occurs;nilotherwise- 반환 형식
errorornil
Sets the start date of a
Calendsobject, based on theCalendsobject’s current value. The inputs are the same as forCreate, above, except the string → value map option isn’t available, since you’re already specifically setting the start value explicitly.
- func (Calends) SetEndDate(stamp interface, calendar string, format string) (Calends, error)
- 매개변수
value (
interface{}) – The value to parse the date/time from.calendar (
string) – The calendar system to parse the date/time with.format (
string) – The format the date/time is expected to use.
- 반환
A new
Calendsobject- 반환 형식
- 반환
errorwhen an error occurs;nilotherwise- 반환 형식
errorornil
Sets the end date of a
Calendsobject, based on theCalendsobject’s current value. The inputs are the same as forCreate, above, except the string → value map option isn’t available, since you’re already specifically setting the end value explicitly.
- func (Calends) SetDuration(duration interface, calendar string) (Calends, error)
- 매개변수
duration (
interface{}) – The value to parse the new duration from.calendar (
string) – The calendar system to parse the date/time with.
- 반환
A new
Calendsobject- 반환 형식
- 반환
errorwhen an error occurs;nilotherwise- 반환 형식
errorornil
Sets the duration of a
Calendsobject, by adjusting its end point, and using the current start point as an anchor. Thedurationvalue is interpreted by the calendar system given incalendar, so is subject to any of its rules.
- func (Calends) SetDurationFromEnd(duration interface, calendar string) (Calends, error)
- 매개변수
duration (
interface{}) – The value to parse the new duration from.calendar (
string) – The calendar system to parse the date/time with.
- 반환
A new
Calendsobject- 반환 형식
- 반환
errorwhen an error occurs;nilotherwise- 반환 형식
errorornil
Sets the duration of a
Calendsobject, by adjusting its start point, and using the current end point as an anchor. Thedurationvalue is interpreted by the calendar system given incalendar, so is subject to any of its rules.
Manipulate
- func (Calends) Add(offset interface, calendar string) (Calends, error)
- 매개변수
offset (
interface{}) – The value to parse the offset from.calendar (
string) – The calendar system to parse the date/time with.
- 반환
A new
Calendsobject- 반환 형식
- 반환
errorwhen an error occurs;nilotherwise- 반환 형식
errorornil
Increases the end date of the
Calendsobject’s current value byoffset, as interpreted by the calendar system given incalendar.
- func (Calends) AddFromEnd(offset interface, calendar string) (Calends, error)
- 매개변수
offset (
interface{}) – The value to parse the offset from.calendar (
string) – The calendar system to parse the date/time with.
- 반환
A new
Calendsobject- 반환 형식
- 반환
errorwhen an error occurs;nilotherwise- 반환 형식
errorornil
Increases the start date of the
Calendsobject’s current value byoffset, as interpreted by the calendar system given incalendar.
- func (Calends) Subtract(offset interface, calendar string) (Calends, error)
- 매개변수
offset (
interface{}) – The value to parse the offset from.calendar (
string) – The calendar system to parse the date/time with.
- 반환
A new
Calendsobject- 반환 형식
- 반환
errorwhen an error occurs;nilotherwise- 반환 형식
errorornil
Works the same as
Add, except it decreases the start date, rather than increasing it.
- func (Calends) SubtractFromEnd(offset interface, calendar string) (Calends, error)
- 매개변수
offset (
interface{}) – The value to parse the offset from.calendar (
string) – The calendar system to parse the date/time with.
- 반환
A new
Calendsobject- 반환 형식
- 반환
errorwhen an error occurs;nilotherwise- 반환 형식
errorornil
Works the same as
AddFromEnd, except it decreases the end date, rather than increasing it.
- func (Calends) Next(offset interface, calendar string) (Calends, error)
- 매개변수
offset (
interface{}) – The value to parse the offset from.calendar (
string) – The calendar system to parse the date/time with.
- 반환
A new
Calendsobject- 반환 형식
- 반환
errorwhen an error occurs;nilotherwise- 반환 형식
errorornil
Returns a
Calendsobject ofoffsetduration (as interpreted by the calendar system given incalendar), which abuts theCalendsobject’s current value. Ifoffsetis empty,calendaris ignored, and the current object’s duration is used instead.
- func (Calends) Previous(offset interface, calendar string) (Calends, error)
- 매개변수
offset (
interface{}) – The value to parse the offset from.calendar (
string) – The calendar system to parse the date/time with.
- 반환
A new
Calendsobject- 반환 형식
- 반환
errorwhen an error occurs;nilotherwise- 반환 형식
errorornil
Returns a
Calendsobject ofoffsetduration (as interpreted by the calendar system given incalendar), which abuts theCalendsobject’s current value. Ifoffsetis empty,calendaris ignored, and the current object’s duration is used instead.
Combine
- func (Calends) Merge(c2 Calends) (Calends, error)
- 매개변수
- 반환
A new
Calendsobject- 반환 형식
- 반환
errorwhen an error occurs;nilotherwise- 반환 형식
errorornil
Returns a
Calendsobject spanning from the earliest start date to the latest end date between the currentCalendsobject andc2.
- func (Calends) Intersect(c2 Calends) (Calends, error)
- 매개변수
- 반환
A new
Calendsobject- 반환 형식
- 반환
errorwhen an error occurs;nilotherwise- 반환 형식
errorornil
Returns a
Calendsobject spanning the overlap between the currentCalendsobject andc2. If the current object andc2don’t overlap, returns an error.
- func (Calends) Gap(c2 Calends) (Calends, error)
- 매개변수
- 반환
A new
Calendsobject- 반환 형식
- 반환
errorwhen an error occurs;nilotherwise- 반환 형식
errorornil
Returns a
Calendsobject spanning the gap between the currentCalendsobject andc2. If the current object andc2overlap (and there is, therefore, no gap to return), returns an error.
Compare
- func (Calends) Difference(c2 Calends, mode string) Float
- 매개변수
- 반환
The difference, as an arbitrary-precision floating point number
- 반환 형식
math/big.Float
Returns the difference of the current
Calendsobject minusc2, usingmodeto select which values to use in the calculation. Validmodes include:start- use the start date of both the current object andc2duration- use the duration of both the current object andc2end- use the end date of both the current object andc2start-end- use the start of the current object, and the end ofc2end-start- use the end of the current object, and the start ofc2
- func (Calends) Compare(c2 Calends, mode string) int
- 매개변수
- 반환
A standard comparison result
- 반환 형식
int
Returns
-1if the currentCalendsobject is less thanc2,0if they are equal, and1if the current object is greater thanc2, usingmodeto select which values to use in the comparison. Validmodes are the same as for(Calends) Difference, above.
- func (Calends) Contains(c2 Calends) bool
-
Checks whether the current
Calendsobject contains all ofc2.
- func (Calends) Overlaps(c2 Calends) bool
-
Checks whether the current
Calendsobject overlaps withc2.
- func (Calends) Abuts(c2 Calends) bool
-
Checks whether the current
Calendsobject abutsc2(that is, whether one begins at the same instant the other ends).
- func (Calends) IsSame(c2 Calends) bool
-
Checks whether the current
Calendsobject covers the same span of time asc2.
- func (Calends) IsShorter(c2 Calends) bool
-
Compares the duration of the current
Calendsobject andc2.
- func (Calends) IsSameDuration(c2 Calends) bool
-
Compares the duration of the current
Calendsobject andc2.
- func (Calends) IsLonger(c2 Calends) bool
-
Compares the duration of the current
Calendsobject andc2.
- func (Calends) IsBefore(c2 Calends) bool
-
Compares the entirety of the current
Calendsobject with the start date ofc2.
- func (Calends) StartsBefore(c2 Calends) bool
-
Compares the start date of the current
Calendsobject with the start date ofc2.
- func (Calends) EndsBefore(c2 Calends) bool
-
Compares the end date of the current
Calendsobject with the start date ofc2.
- func (Calends) IsDuring(c2 Calends) bool
-
Checks whether the entirety of the current
Calendsobject lies between the start and end dates ofc2.
- func (Calends) StartsDuring(c2 Calends) bool
-
Checks whether the start date of the current
Calendsobject lies between the start and end dates ofc2.
- func (Calends) EndsDuring(c2 Calends) bool
-
Checks whether the end date of the current
Calendsobject lies between the start and end dates ofc2.
- func (Calends) IsAfter(c2 Calends) bool
-
Compares the entirety of the current
Calendsobject with the end date ofc2.
Export
- func (Calends) String() string
- 반환
The string representation of the current value.
- 반환 형식
string
Implements the
fmt.Stringerinterface.
- func (Calends) MarshalText() ([]byte, error)
- 반환
A byte slice containing the marshalled text.
- 반환 형식
[]byte- 반환
Any error that occurs.
- 반환 형식
error
Implements the
encoding.TextMarshalerinterface.
- func (*Calends) UnmarshalText(in []byte) error
- 매개변수
in (
[]byte) – A byte slice containing the marshalled text.
- 반환
Any error that occurs.
- 반환 형식
error
Implements the
encoding.TextUnmarshalerinterface.
- func (Calends) MarshalJSON() ([]byte, error)
- 반환
A byte slice containing the marshalled JSON.
- 반환 형식
[]byte- 반환
Any error that occurs.
- 반환 형식
error
Implements the
encoding/json.Marshalerinterface.
- func (*Calends) UnmarshalJSON(in []byte) error
- 매개변수
in (
[]byte) – A byte slice containing the marshalled JSON.
- 반환
Any error that occurs.
- 반환 형식
error
Implements the
encoding/json.Unmarshalerinterface.