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 Compare(a, b Date) int
- func DaysBetween(a, b Date) (int, error)
- func DaysInMonth(year, month int) (int, error)
- func DaysInYear(year int) (int, error)
- func FromNepaliDigits(s string) string
- func IsSupportedBSYear(year int) bool
- func IsValid(year, month, day int) bool
- func MonthName(month int) (string, error)
- func MonthNameNepali(month int) (string, error)
- func ToNepaliDigits(s string) string
- 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) DayOfYear() (int, error)
- func (d Date) EndOfMonth() (Date, error)
- func (d Date) EndOfYear() (Date, error)
- func (d Date) Equal(other Date) bool
- func (d Date) Format(layout string) (string, error)
- func (d Date) MonthName() (string, error)
- func (d Date) MonthNameNepali() (string, error)
- func (d Date) StartOfMonth() (Date, error)
- func (d Date) StartOfYear() (Date, error)
- func (d Date) String() string
- func (d Date) SubDays(n int) (Date, error)
- 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 Compare ¶ added in v0.2.0
Compare compares two dates and returns -1 if a is before b, 0 if they're equal, and 1 if a is after b. It compares fields directly and does not require either date to be valid.
func DaysBetween ¶ added in v0.2.0
DaysBetween returns the number of calendar days from a to b: positive if b is after a, negative if b is before a, zero if they're equal. It returns an error wrapping ErrInvalidYear, ErrInvalidMonth or ErrInvalidDay if either date is invalid.
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 FromNepaliDigits ¶ added in v0.3.0
FromNepaliDigits replaces every Devanagari digit (०-९) in s with its ASCII equivalent (e.g. "२०८३" becomes "2083"). Other characters, including existing ASCII digits, are copied through unchanged.
func IsSupportedBSYear ¶
IsSupportedBSYear reports whether year is within MinBSYear..MaxBSYear.
func IsValid ¶
IsValid reports whether year, month and day form a real Bikram Sambat calendar date within the supported range (MinBSYear..MaxBSYear).
func MonthName ¶
MonthName returns the English name of the given 1-based Bikram Sambat month (1 is Baisakh, 12 is Chaitra).
func MonthNameNepali ¶ added in v0.3.0
MonthNameNepali returns the Devanagari name of the given 1-based Bikram Sambat month (1 is Baisakh, 12 is Chaitra).
func ToNepaliDigits ¶ added in v0.3.0
ToNepaliDigits replaces every ASCII digit (0-9) in s with its Devanagari equivalent (e.g. "2083" becomes "२०८३"). Non-digit characters, including punctuation and existing Devanagari digits, are copied through unchanged.
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.
func (Date) DayOfYear ¶ added in v0.2.0
DayOfYear returns d's 1-based ordinal day within its year (1 for Baisakh 1, up to 365 or 366 for the last day of Chaitra). It returns an error wrapping ErrInvalidYear, ErrInvalidMonth or ErrInvalidDay if d is not a valid date.
func (Date) EndOfMonth ¶ added in v0.2.0
EndOfMonth returns the last day of d's month. It returns an error wrapping ErrInvalidYear or ErrInvalidMonth if d's year or month is invalid.
func (Date) EndOfYear ¶ added in v0.2.0
EndOfYear returns the last day of Chaitra of d's year. It returns an error wrapping ErrInvalidYear if d's year is invalid.
func (Date) Format ¶ added in v0.3.0
Format renders d according to layout, replacing recognized tokens:
YYYY 4-digit year, e.g. "2083" YY 2-digit year, e.g. "83" MMMM full month name, e.g. "Ashwin" MM 2-digit month, zero-padded M month, no leading zero DD 2-digit day, zero-padded D day, no leading zero dddd full weekday name, e.g. "Thursday" ddd 3-letter weekday abbreviation, e.g. "Thu"
Any other character in layout (including punctuation and spaces) is copied through unchanged. It returns an error wrapping ErrInvalidYear, ErrInvalidMonth or ErrInvalidDay if d is not a valid date.
func (Date) MonthNameNepali ¶ added in v0.3.0
MonthNameNepali returns the Devanagari name of d's month.
func (Date) StartOfMonth ¶ added in v0.2.0
StartOfMonth returns the first day (day 1) of d's month. It returns an error wrapping ErrInvalidYear or ErrInvalidMonth if d's year or month is invalid.
func (Date) StartOfYear ¶ added in v0.2.0
StartOfYear returns Baisakh 1 of d's year. It returns an error wrapping ErrInvalidYear if d's year is invalid.
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). |