Documentation ¶
Overview ¶
Package isoweek calculates a starting date and time of ISO 8601 week.
ISO 8601 standard defines the common week number system used in Europe and many other countries. Monday is the first day of a week.
The Go standard library time package has time.Time.ISOWeek function for getting ISO 8601 week number of a given time.Time, but there is no reverse functionality for getting a date from a week number. This package implements that.
Invalid input is silently accepted. There is a separate Validate function if week number validation is needed.
There are also functions for working with Julian day numbers. Using Julian day numbers is often the easiest and fastest way to do date calculations.
This package does not work with the "traditional" week system used in US/Canada/Japan/etc. (weeks starting on Sundays). However the Julian day number functions may be still useful.
Index ¶
- func DateToJulian(year int, month time.Month, day int) (jdn int)
- func FromDate(year int, month time.Month, day int) (wyear, week int)
- func ISOWeekday(year int, month time.Month, day int) (weekday int)
- func JulianToDate(jdn int) (year int, month time.Month, day int)
- func StartDate(wyear, week int) (year int, month time.Month, day int)
- func StartTime(wyear, week int, loc *time.Location) (start time.Time)
- func Validate(wyear, week int) (ok bool)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DateToJulian ¶
DateToJulian converts a date to a Julian day number.
Example ¶
package main import ( "fmt" "github.com/snabb/isoweek" ) func main() { fmt.Println(isoweek.DateToJulian(2006, 1, 2)) }
Output: 2453738
func FromDate ¶
FromDate returns ISO 8601 week number of a date.
Example ¶
package main import ( "fmt" "github.com/snabb/isoweek" ) func main() { fmt.Println(isoweek.FromDate(1984, 1, 1)) }
Output: 1983 52
func ISOWeekday ¶
ISOWeekday returns the ISO 8601 weekday number of given day. (1 = Mon, 2 = Tue,.. 7 = Sun)
This is different from Go's standard time.Weekday.
Example ¶
package main import ( "fmt" "github.com/snabb/isoweek" ) func main() { fmt.Println(isoweek.ISOWeekday(1984, 1, 1)) }
Output: 7
func JulianToDate ¶
JulianToDate converts a Julian day number to a date.
Example ¶
package main import ( "fmt" "github.com/snabb/isoweek" ) func main() { fmt.Println(isoweek.JulianToDate(2453738)) }
Output: 2006 January 2
func StartDate ¶
StartDate returns the starting date (Monday) of the given ISO 8601 week.
Example ¶
package main import ( "fmt" "github.com/snabb/isoweek" ) func main() { y, m, d := isoweek.StartDate(2000, 1) fmt.Println(d, m, y) }
Output: 3 January 2000
func StartTime ¶
StartTime returns the starting time (Monday 00:00) of the given ISO 8601 week.
Example ¶
package main import ( "fmt" "time" "github.com/snabb/isoweek" ) func main() { t := isoweek.StartTime(1985, 1, time.UTC) fmt.Println(t) }
Output: 1984-12-31 00:00:00 +0000 UTC
func Validate ¶
Validate checks if a week number is valid. Returns true if it is valid.
Example ¶
package main import ( "fmt" "github.com/snabb/isoweek" ) func main() { fmt.Println( isoweek.Validate(2015, 52), isoweek.Validate(2015, 53), isoweek.Validate(2015, 54), isoweek.Validate(2016, 0), isoweek.Validate(2016, 1)) fmt.Println( isoweek.Validate(2016, 52), isoweek.Validate(2016, 53), isoweek.Validate(2016, 54), isoweek.Validate(2017, 0), isoweek.Validate(2017, 1)) }
Output: true true false false true true false false false true
Types ¶
This section is empty.