Documentation
¶
Overview ¶
Code generated by tools/calendar-generator. DO NOT EDIT.
Regenerate with: go run ./tools/calendar-generator -out data.go See docs/calendar-data.md for sources and verification method.
Package bs converts calendar dates between the Gregorian (AD) calendar and the Bikram Sambat (BS) calendar used in Nepal, for BS years MinBSYear through MaxBSYear inclusive.
BS month lengths are not derived from a formula: they follow Nepal's officially published calendar and are stored as a verified, table-driven dataset (see docs/calendar-data.md for sources). The package has no runtime dependencies.
Conversion operates on calendar dates (year, month, day), not timestamps. ADToBS considers only the Year, Month and Day components of the given time.Time and ignores time-of-day and location.
Index ¶
- Constants
- Variables
- func BSToAD(d Date) (time.Time, error)
- func DaysInMonth(year, month int) (int, error)
- func DaysInYear(year int) (int, error)
- func IsSupportedBSYear(year int) bool
- func IsValid(year, month, day int) bool
- func MonthName(month int) (string, error)
- type Date
- func (d Date) AddDays(n int) (Date, error)
- func (d Date) After(other Date) bool
- func (d Date) Before(other Date) bool
- func (d Date) DayOfWeek() (time.Weekday, error)
- func (d Date) Equal(other Date) bool
- func (d Date) MonthName() (string, error)
- func (d Date) String() string
- func (d Date) Valid() bool
Constants ¶
const ( MinBSYear = 1979 MaxBSYear = 2100 )
MinBSYear and MaxBSYear are the inclusive bounds of the BS years supported by this package.
Variables ¶
var ( // ErrInvalidYear is returned when a BS year is outside MinBSYear..MaxBSYear. ErrInvalidYear = errors.New("bs: invalid year") // ErrInvalidMonth is returned when a BS month is not in the range 1..12. ErrInvalidMonth = errors.New("bs: invalid month") // ErrInvalidDay is returned when a BS day is not a valid day of the given // month (either out of the generic 1..32 bound, or greater than the // actual number of days in that month/year). ErrInvalidDay = errors.New("bs: invalid day") // ErrOutOfRange is returned when an AD date falls outside the Gregorian // range corresponding to MinBSYear..MaxBSYear. ErrOutOfRange = errors.New("bs: date outside supported range") // ErrInvalidFormat is returned when a string passed to Parse is not // shaped like "YYYY-MM-DD". ErrInvalidFormat = errors.New("bs: invalid date format") )
Sentinel errors returned by this package. Use errors.Is to check for them; wrapped errors include additional context via fmt.Errorf's %w verb.
Functions ¶
func BSToAD ¶
BSToAD converts a Bikram Sambat date to the corresponding Gregorian calendar date, returned as a time.Time at UTC midnight. It returns an error wrapping ErrInvalidYear, ErrInvalidMonth or ErrInvalidDay if d is not a real, supported Bikram Sambat date.
func DaysInMonth ¶
DaysInMonth returns the number of days in the given Bikram Sambat month. It returns ErrInvalidYear or ErrInvalidMonth if year or month is out of range.
func DaysInYear ¶
DaysInYear returns the total number of days in the given Bikram Sambat year. It returns ErrInvalidYear if year is out of range.
func IsSupportedBSYear ¶
IsSupportedBSYear reports whether year is within MinBSYear..MaxBSYear.
Types ¶
type Date ¶
Date represents a Bikram Sambat calendar date. Month is 1-based, where 1 is Baisakh and 12 is Chaitra. A Date is not guaranteed to be valid unless it was constructed with NewDate or returned by this package.
func ADToBS ¶
ADToBS converts a Gregorian calendar date to Bikram Sambat. Only the Year, Month and Day components of t are used; time-of-day and location are ignored. It returns an error wrapping ErrOutOfRange if t falls outside the Gregorian range corresponding to MinBSYear..MaxBSYear.
func NewDate ¶
NewDate constructs a Date and validates it. It returns an error wrapping ErrInvalidYear, ErrInvalidMonth or ErrInvalidDay if the given components do not form a real Bikram Sambat calendar date in the supported range.
func Parse ¶
Parse parses a Bikram Sambat date in "YYYY-MM-DD" format (the same format Date.String produces). It returns an error wrapping ErrInvalidFormat if s is not shaped like a date, or ErrInvalidYear, ErrInvalidMonth or ErrInvalidDay if it's shaped correctly but not a real supported date.
func (Date) AddDays ¶
AddDays returns the date n calendar days after d (or before, if n is negative). It returns an error wrapping ErrInvalidYear, ErrInvalidMonth or ErrInvalidDay if d is not itself a valid date, or ErrOutOfRange if the result falls outside the supported range.
func (Date) After ¶
After reports whether d is chronologically after other. It compares fields directly and does not require either date to be valid.
func (Date) Before ¶
Before reports whether d is chronologically before other. It compares fields directly and does not require either date to be valid.
func (Date) DayOfWeek ¶
DayOfWeek returns the day of the week d falls on, derived through its equivalent Gregorian date. It returns an error wrapping ErrInvalidYear, ErrInvalidMonth or ErrInvalidDay if d is not a valid date.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
tools
|
|
|
calendar-generator
command
Command calendar-generator produces the ../../data.go calendar dataset for package bs (github.com/suprimkhatri77/go-bs).
|
Command calendar-generator produces the ../../data.go calendar dataset for package bs (github.com/suprimkhatri77/go-bs). |