Documentation
¶
Overview ¶
Package dateparse parses date-strings without knowing the format in advance, using a fast lex based approach to eliminate shotgun attempts. Validates comprehensively to avoid false positives.
By default it leans towards US style dates when there is a conflict. This can be adjusted using the `PreferMonthFirst` parser option. Some ambiguous formats can fail (e.g., trying to parse `31/03/2023“ as the default month-first format `MM/DD/YYYY`), but can be automatically retried with `RetryAmbiguousDateWithSwap`.
Consider turning on the the `SimpleErrorMessages` option if you will be attempting to parse many strings that do not match any known format and you need to maximize performance.
See README.md for key points on how timezone/location parsing works in go, as this can be counterintuitive initially.
Index ¶
- Constants
- Variables
- func AddBusinessDays(t time.Time, n int, holidays []time.Time) time.Time
- func AgeDetailed(birthDate, targetDate time.Time) (years, months, days int)
- func AgeDetailedToNow(birthDate time.Time) (years, months, days int)
- func BeginningOfMonth(date time.Time) time.Time
- func BeginningOfWeek(date time.Time) time.Time
- func BeginningOfYear(date time.Time) time.Time
- func BusinessDaysBetween(a, b time.Time, holidays []time.Time) int
- func Calculate(startTime, endTime time.Time) int
- func CalculateToNow(givenTime time.Time) int
- func CalendarWeeks(year int, month time.Month) [][]time.Time
- func Clamp(t, minT, maxT time.Time) time.Time
- func ConvertTZ(t time.Time, to string) (time.Time, error)
- func DayOfYear(t time.Time) int
- func DaysInMonth(year int, month time.Month) int
- func DaysSince(t time.Time) int
- func DaysUntil(t time.Time) int
- func EasterDate(year int) time.Time
- func EndOfDay(t time.Time) time.Time
- func EndOfMonth(t time.Time) time.Time
- func EndOfQuarter(t time.Time) time.Time
- func EndOfWeek(t time.Time, startDay ...time.Weekday) time.Time
- func EndOfYear(t time.Time) time.Time
- func EnglishToNepali(year int, month int, day int) (*[3]int, error)
- func Format(t time.Time, layout string) string
- func FormatDate(t time.Time) string
- func FormatDateTime(t time.Time) string
- func FormatDateTimeMs(t time.Time) string
- func FormatDuration(d time.Duration, short bool) string
- func FormatHuman(t time.Time) string
- func FormatHumanTime(t time.Time) string
- func FormatRFC3339(t time.Time) string
- func FormatRFC3339Nano(t time.Time) string
- func GetCurrentEnglishTime() time.Time
- func GetNepaliLocation() *time.Location
- func GuessTimezone(abbr string) (string, bool)
- func HumanizeDuration(d time.Duration) string
- func IsHoliday(t time.Time, holidays []time.Time) bool
- func IsLeapYear(givenYear int) bool
- func IsSameDay(a, b time.Time) bool
- func IsSameMonth(a, b time.Time) bool
- func IsSameWeek(a, b time.Time) bool
- func IsSameYear(a, b time.Time) bool
- func IsValidTimezone(zone string) bool
- func IsWeekday(t time.Time) bool
- func IsWeekend(t time.Time) bool
- func LastWeekdayOfMonth(year int, month time.Month, weekday time.Weekday) time.Time
- func LoadLocation(zone string) (*time.Location, error)
- func LocalToUTC(t time.Time) time.Time
- func MonthName(m time.Month) string
- func MonthsBetween(a, b time.Time) int
- func MustParse(datestr string, opts ...ParserOption) time.Time
- func NepaliToEnglish(year int, month int, day int) (*[3]int, error)
- func NextLeapYear(givenYear int) (foundYear int, found bool)
- func NthWeekdayOfMonth(year int, month time.Month, weekday time.Weekday, n int) time.Time
- func Ordinal(n int) string
- func Parse(datestr string, opts ...ParserOption) (time.Time, error)
- func ParseDuration(s string) (time.Duration, error)
- func ParseFormat(datestr string, opts ...ParserOption) (string, error)
- func ParseIn(datestr string, loc *time.Location, opts ...ParserOption) (time.Time, error)
- func ParseInTimezone(s, zone string) (time.Time, error)
- func ParseLocal(datestr string, opts ...ParserOption) (time.Time, error)
- func ParseStrict(datestr string, opts ...ParserOption) (time.Time, error)
- func ParseTimestamp(v int64) time.Time
- func ParseTimestampString(s string) (time.Time, error)
- func Pretty(pretty bool) func(*gparser) error
- func PrevLeapYear(givenYear int) (foundYear int, found bool)
- func Quarter(t time.Time) int
- func RelativeTime(t, ref time.Time) string
- func RoundDuration(d, unit time.Duration) time.Duration
- func ShortMonthName(m time.Month) string
- func ShortWeekdayName(w time.Weekday) string
- func Size(size int) func(*gparser) error
- func StartOfDay(t time.Time) time.Time
- func StartOfMonth(t time.Time) time.Time
- func StartOfQuarter(t time.Time) time.Time
- func StartOfWeek(t time.Time, startDay ...time.Weekday) time.Time
- func StartOfYear(t time.Time) time.Time
- func TimeElapsed(now time.Time, then time.Time, full bool) string
- func TimestampPrecisionOf(v int64) string
- func TimezoneOffset(zone string, t time.Time) (int, error)
- func ToUnix(t time.Time) int64
- func ToUnixMicro(t time.Time) int64
- func ToUnixMilli(t time.Time) int64
- func ToUnixNano(t time.Time) int64
- func TruncateDuration(d, unit time.Duration) time.Duration
- func UTCToLocal(t time.Time) time.Time
- func UnixMicroToTime(us int64) time.Time
- func UnixMilliToTime(ms int64) time.Time
- func UnixNanoToTime(ns int64) time.Time
- func UnixToTime(unix int64) time.Time
- func WeekNumber(t time.Time) int
- func WeekdayName(w time.Weekday) string
- func WeeksBetween(a, b time.Time) int
- type DateDiff
- type DateRange
- func (r DateRange) BusinessDays(holidays []time.Time) []time.Time
- func (r DateRange) Contains(t time.Time) bool
- func (r DateRange) Days() int
- func (r DateRange) Duration() time.Duration
- func (r DateRange) Each(fn func(time.Time) bool)
- func (r DateRange) EachMonth(fn func(time.Time) bool)
- func (r DateRange) Extend(d time.Duration) DateRange
- func (r DateRange) Intersect(other DateRange) (DateRange, bool)
- func (r DateRange) IsEmpty() bool
- func (r DateRange) Overlaps(other DateRange) bool
- func (r DateRange) Shift(d time.Duration) DateRange
- func (r DateRange) Split(d time.Duration) []DateRange
- func (r DateRange) Union(other DateRange) DateRange
- type Direction
- type ExprType
- type NepaliFormatter
- type NepaliMonthData
- type NepaliTime
- func (obj *NepaliTime) Clock() (hour, min, sec int)
- func (obj *NepaliTime) Date() (year, month, day int)
- func (obj *NepaliTime) Day() int
- func (obj *NepaliTime) Format(format string) (string, error)
- func (obj *NepaliTime) GetEnglishTime() time.Time
- func (obj *NepaliTime) Hour() int
- func (obj *NepaliTime) Minute() int
- func (obj *NepaliTime) Month() int
- func (obj *NepaliTime) Nanosecond() int
- func (obj *NepaliTime) Second() int
- func (obj *NepaliTime) String() string
- func (obj *NepaliTime) Weekday() time.Weekday
- func (obj *NepaliTime) Year() int
- type Option
- type ParserOption
Constants ¶
const ( ExprTypeInvalid = 0 ExprTypeDate = ExprType(1 << iota) ExprTypeTime ExprTypeNow ExprTypeRelativeMinutes ExprTypeRelativeHours ExprTypeRelativeDays ExprTypeRelativeWeeks ExprTypeRelativeWeekdays ExprTypeRelativeMonth ExprTypeRelativeYear ExprTypeClock12Hour ExprTypeClock24Hour )
const (
Timezone string = "Asia/Kathmandu"
)
Variables ¶
var ( // ErrAmbiguousMMDD for date formats such as 04/02/2014 the mm/dd vs dd/mm are // ambiguous, so it is an error for strict parse rules. ErrAmbiguousMMDD = fmt.Errorf("this date has ambiguous mm/dd vs dd/mm type format") ErrCouldntFindFormat = fmt.Errorf("could not find format for") ErrUnexpectedTail = fmt.Errorf("unexpected content after date/time: ") ErrUnknownTZOffset = fmt.Errorf("TZ offset not recognized") ErrUnknownTimeZone = fmt.Errorf("timezone not recognized") ErrFracSecTooLong = fmt.Errorf("fractional seconds too long") )
Functions ¶
func AddBusinessDays ¶ added in v0.0.5
AddBusinessDays adds n business days to t, skipping weekends and any dates in the optional holidays slice. n may be negative to go backwards.
func AgeDetailed ¶ added in v0.0.5
AgeDetailed returns the exact difference in years, months, and days between birthDate and targetDate. If targetDate is before birthDate, they are swapped.
func AgeDetailedToNow ¶ added in v0.0.5
AgeDetailedToNow returns the exact difference in years, months, and days between birthDate and now.
func BusinessDaysBetween ¶ added in v0.0.5
BusinessDaysBetween counts the number of business days between a and b (exclusive of a, inclusive of b direction), skipping weekends and holidays. Returns a negative number if b is before a.
func Calculate ¶ added in v0.0.4
Calculate returns an integer-value age based on the duration between the two times that are given as arguments.
func CalculateToNow ¶ added in v0.0.4
CalculateToNow returns an integer-value age based on the duration between the given time and the present time.
func CalendarWeeks ¶ added in v0.0.5
CalendarWeeks returns the weeks of the given year and month as a 2-D slice. Each inner slice is a 7-element array [Sunday … Saturday]; days that fall outside the month are represented as the zero time.Time.
func Clamp ¶ added in v0.0.5
Clamp returns t if it is within [min, max]; otherwise it returns min or max.
func ConvertTZ ¶ added in v0.0.5
ConvertTZ converts t from its current timezone to the named IANA timezone.
func DayOfYear ¶ added in v0.0.5
DayOfYear returns the day of the year for t (1–365 or 1–366 for leap years).
func DaysInMonth ¶ added in v0.0.5
DaysInMonth returns the number of days in the given month and year.
func DaysSince ¶ added in v0.0.5
DaysSince returns the number of whole calendar days that have elapsed since t. Returns a negative number if t is in the future.
func DaysUntil ¶ added in v0.0.5
DaysUntil returns the number of whole calendar days from now until t. Returns a negative number if t is in the past.
func EasterDate ¶ added in v0.0.5
EasterDate returns the date of Easter Sunday for the given Gregorian year using the Anonymous Gregorian algorithm.
func EndOfMonth ¶ added in v0.0.4
EndOfMonth returns the last instant of t's month.
func EndOfQuarter ¶ added in v0.0.5
EndOfQuarter returns the last instant of the quarter in which t falls.
func EndOfWeek ¶ added in v0.0.5
EndOfWeek returns the last instant of the week that contains t. startDay specifies which weekday begins the week (default: time.Monday).
func EnglishToNepali ¶ added in v0.0.4
Converts english date to nepali. Accepts the input parameters year, month, day. Returns dates in array and error.
func Format ¶ added in v0.0.5
Format formats t using a strftime-style layout string. Most POSIX strftime directives are supported.
func FormatDate ¶ added in v0.0.5
FormatDate formats t as "YYYY-MM-DD".
func FormatDateTime ¶ added in v0.0.5
FormatDateTime formats t as "YYYY-MM-DD HH:MM:SS".
func FormatDateTimeMs ¶ added in v0.0.5
FormatDateTimeMs formats t as "YYYY-MM-DD HH:MM:SS.mmm".
func FormatDuration ¶ added in v0.0.5
FormatDuration formats d as a human-readable string. If short is true, abbreviated units are used (e.g. "2d 3h 15m 5s"). If short is false, full unit names are used (e.g. "2 days 3 hours 15 minutes 5 seconds"). Only non-zero components are included.
func FormatHuman ¶ added in v0.0.5
FormatHuman returns a friendly date string like "Wednesday, January 15, 2025".
func FormatHumanTime ¶ added in v0.0.5
FormatHumanTime returns a friendly datetime string like "Wednesday, January 15, 2025 at 3:04 PM".
func FormatRFC3339 ¶ added in v0.0.5
FormatRFC3339 formats t as RFC 3339 (a profile of ISO 8601).
func FormatRFC3339Nano ¶ added in v0.0.5
FormatRFC3339Nano formats t as RFC 3339 with nanosecond precision.
func GetCurrentEnglishTime ¶ added in v0.0.4
Gets current English date along with time level precision. Current Time of Asia/Kathmandu
func GetNepaliLocation ¶ added in v0.0.4
Returns location for Asia/Kathmandu (constants.Timezone)
func GuessTimezone ¶ added in v0.0.5
GuessTimezone maps a common timezone abbreviation (e.g. "IST", "PST") to a canonical IANA timezone name. It returns the name and true on success, or ("", false) when the abbreviation is not recognized.
func HumanizeDuration ¶ added in v0.0.5
HumanizeDuration returns a coarse, human-friendly description of d such as "just now", "about 3 minutes", "2 hours", "3 days", "about 2 months", etc.
func IsHoliday ¶ added in v0.0.5
IsHoliday reports whether t (at day granularity) matches any date in the holidays slice.
func IsLeapYear ¶ added in v0.0.4
IsLeapYear returns true only if the given year contains a leap day, meaning that the year is a leap year.
func IsSameDay ¶ added in v0.0.5
IsSameDay reports whether a and b fall on the same calendar day (ignoring clock time and timezone differences).
func IsSameMonth ¶ added in v0.0.5
IsSameMonth reports whether a and b fall in the same month of the same year.
func IsSameWeek ¶ added in v0.0.5
IsSameWeek reports whether a and b fall in the same ISO week of the same year.
func IsSameYear ¶ added in v0.0.5
IsSameYear reports whether a and b fall in the same year.
func IsValidTimezone ¶ added in v0.0.5
IsValidTimezone reports whether zone is a recognized IANA timezone name.
func LastWeekdayOfMonth ¶ added in v0.0.5
LastWeekdayOfMonth returns the last occurrence of weekday in the given year and month.
func LoadLocation ¶ added in v0.0.5
LoadLocation is a convenience wrapper around time.LoadLocation that returns a descriptive error.
func LocalToUTC ¶ added in v0.0.5
LocalToUTC converts t to UTC.
func MonthsBetween ¶ added in v0.0.5
MonthsBetween returns the approximate number of whole calendar months between a and b (based on year/month arithmetic, ignoring day-of-month).
func MustParse ¶
func MustParse(datestr string, opts ...ParserOption) time.Time
MustParse parse a date, and panic if it can't be parsed. Used for testing. Not recommended for most use-cases.
func NepaliToEnglish ¶ added in v0.0.4
Converts nepali date to english. Accepts the input parameters year, month, day. Returns dates in array and error.
func NextLeapYear ¶ added in v0.0.4
NextLeapYear returns the next leap year after a given year. It also returns a boolean value that is set to false if no such year can be found.
func NthWeekdayOfMonth ¶ added in v0.0.5
NthWeekdayOfMonth returns the nth occurrence of weekday in the given year and month. For example, NthWeekdayOfMonth(2024, time.November, time.Thursday, 4) returns the 4th Thursday of November 2024 (US Thanksgiving). n must be in [1, 5]. If the month does not have an nth occurrence, the zero Time is returned.
func Ordinal ¶ added in v0.0.5
Ordinal returns the English ordinal suffix string for n (e.g. 1→"1st", 2→"2nd", 11→"11th", 23→"23rd").
func Parse ¶
func Parse(datestr string, opts ...ParserOption) (time.Time, error)
Parse parse an unknown date format, detect the layout. Normal parse. Equivalent Timezone rules as time.Parse(). NOTE: please see readme on mmdd vs ddmm ambiguous dates.
func ParseDuration ¶ added in v0.0.5
ParseDuration parses a human-readable duration string and returns the equivalent time.Duration. It supports Go's native format (e.g. "1h30m") as a fallback, plus extended human forms such as:
"2d 3h 15m" "1 week 2 days" "90 seconds" "2y 3mo 1w 4d 5h 30m 15s"
func ParseFormat ¶
func ParseFormat(datestr string, opts ...ParserOption) (string, error)
ParseFormat parses an unknown date-time string and returns a layout string that can parse this (and exact same format) other date-time strings.
In certain edge cases, this may produce a format string of a different length than the input string. If this happens, it's an edge case that requires individually parsing each time.
layout, err := dateparse.ParseFormat("2013-02-01 00:00:00")
// layout = "2006-01-02 15:04:05"
func ParseIn ¶
ParseIn with Location, equivalent to time.ParseInLocation() timezone/offset rules. Using location arg, if timezone/offset info exists in the datestring, it uses the given location rules for any zone interpretation. That is, MST means one thing when using America/Denver and something else in other locations. See README for a more detailed explanation.
func ParseInTimezone ¶ added in v0.0.5
ParseInTimezone parses the date string s using dateparse.ParseAny and then reinterprets the resulting time as being in the named IANA timezone. Use this when the date string carries no timezone information.
func ParseLocal ¶
func ParseLocal(datestr string, opts ...ParserOption) (time.Time, error)
ParseLocal Given an unknown date format, detect the layout, using time.Local, parse.
Set Location to time.Local. Same as ParseIn Location but lazily uses the global time.Local variable for Location argument.
denverLoc, _ := time.LoadLocation("America/Denver")
time.Local = denverLoc
t, err := dateparse.ParseLocal("3/1/2014")
Equivalent to:
t, err := dateparse.ParseIn("3/1/2014", denverLoc)
func ParseStrict ¶
func ParseStrict(datestr string, opts ...ParserOption) (time.Time, error)
ParseStrict parse an unknown date format. IF the date is ambigous mm/dd vs dd/mm then return an error. These return errors: 3.3.2014 , 8/8/71 etc
func ParseTimestamp ¶ added in v0.0.5
ParseTimestamp auto-detects whether v is a Unix timestamp in seconds, milliseconds, microseconds, or nanoseconds and returns the corresponding time.Time (UTC).
func ParseTimestampString ¶ added in v0.0.5
ParseTimestampString parses a numeric string as a Unix timestamp, applying the same auto-detection as ParseTimestamp. Returns an error if the string is not a valid integer.
func PrevLeapYear ¶ added in v0.0.4
PrevLeapYear returns the previous leap year before a given year. It also returns a boolean value that is set to false if no such year can be found.
func RelativeTime ¶ added in v0.0.5
RelativeTime returns a human-readable string describing t relative to ref, such as "3 days ago", "in 2 hours", "just now", "yesterday", "tomorrow".
func RoundDuration ¶ added in v0.0.5
RoundDuration rounds d to the nearest multiple of unit.
func ShortMonthName ¶ added in v0.0.5
ShortMonthName returns the 3-letter English abbreviation of the given month.
func ShortWeekdayName ¶ added in v0.0.5
ShortWeekdayName returns the 3-letter English abbreviation of the given weekday.
func StartOfDay ¶ added in v0.0.5
StartOfDay returns t truncated to the beginning of its day (00:00:00.000000000).
func StartOfMonth ¶ added in v0.0.5
StartOfMonth returns the first moment of t's month.
func StartOfQuarter ¶ added in v0.0.5
StartOfQuarter returns the first moment of the quarter in which t falls.
func StartOfWeek ¶ added in v0.0.5
StartOfWeek returns the start of the week that contains t. startDay specifies which weekday begins the week (default: time.Monday).
func StartOfYear ¶ added in v0.0.5
StartOfYear returns the first moment of t's year.
func TimeElapsed ¶ added in v0.0.4
func TimestampPrecisionOf ¶ added in v0.0.5
TimestampPrecisionOf returns a string describing the auto-detected precision of a numeric timestamp value ("seconds", "milliseconds", "microseconds", "nanoseconds").
func TimezoneOffset ¶ added in v0.0.5
TimezoneOffset returns the UTC offset in seconds for the named IANA timezone at the moment represented by t.
func ToUnixMicro ¶ added in v0.0.5
ToUnixMicro returns the Unix time in microseconds of t.
func ToUnixMilli ¶ added in v0.0.5
ToUnixMilli returns the Unix time in milliseconds of t.
func ToUnixNano ¶ added in v0.0.5
ToUnixNano returns the Unix time in nanoseconds of t.
func TruncateDuration ¶ added in v0.0.5
TruncateDuration truncates d to a multiple of unit (towards zero).
func UTCToLocal ¶ added in v0.0.5
UTCToLocal converts a UTC time to the system local timezone.
func UnixMicroToTime ¶ added in v0.0.5
UnixMicroToTime converts a Unix timestamp in microseconds to time.Time (UTC).
func UnixMilliToTime ¶ added in v0.0.5
UnixMilliToTime converts a Unix timestamp in milliseconds to time.Time (UTC).
func UnixNanoToTime ¶ added in v0.0.5
UnixNanoToTime converts a Unix timestamp in nanoseconds to time.Time (UTC).
func UnixToTime ¶ added in v0.0.5
UnixToTime converts a Unix timestamp (seconds since epoch) to time.Time (UTC).
func WeekNumber ¶ added in v0.0.5
WeekNumber returns the ISO 8601 week number for t.
func WeekdayName ¶ added in v0.0.5
WeekdayName returns the full English name of the given weekday.
func WeeksBetween ¶ added in v0.0.5
WeeksBetween returns the number of complete weeks between a and b.
Types ¶
type DateDiff ¶ added in v0.0.5
DateDiff holds the component-wise difference between two time.Time values.
func DiffDetailed ¶ added in v0.0.5
DiffDetailed returns the component-wise difference between from and to. All fields are non-negative; the caller can determine direction by comparing the original times.
type DateRange ¶ added in v0.0.5
DateRange represents an inclusive range between two points in time.
func NewDateRange ¶ added in v0.0.5
NewDateRange creates a DateRange. It returns an error if end is before start.
func NewDateRangeFromDuration ¶ added in v0.0.5
NewDateRangeFromDuration creates a DateRange starting at start with the given duration.
func (DateRange) BusinessDays ¶ added in v0.0.5
BusinessDays returns a slice of all business days (Mon–Fri, excluding holidays) within the range, one entry per day at start-of-day.
func (DateRange) Contains ¶ added in v0.0.5
Contains reports whether t falls within [Start, End] (inclusive).
func (DateRange) Days ¶ added in v0.0.5
Days returns the number of whole calendar days spanned by the range. A range within a single day returns 1.
func (DateRange) Duration ¶ added in v0.0.5
Duration returns the duration of the range (End − Start).
func (DateRange) Each ¶ added in v0.0.5
Each calls fn once for each calendar day in the range (inclusive), passing the start-of-day time. Iteration stops early if fn returns false.
func (DateRange) EachMonth ¶ added in v0.0.5
EachMonth calls fn once for the first day of each calendar month that overlaps the range. Iteration stops early if fn returns false.
func (DateRange) Intersect ¶ added in v0.0.5
Intersect returns the intersection of r and other, plus a boolean indicating whether the intersection is non-empty.
func (DateRange) Overlaps ¶ added in v0.0.5
Overlaps reports whether r and other share any point in time.
func (DateRange) Shift ¶ added in v0.0.5
Shift returns a new DateRange shifted forward (positive d) or backward (negative d).
type Direction ¶ added in v0.0.4
type Direction int
Direction is the direction used for ambiguous expressions.
type ExprType ¶ added in v0.0.4
type ExprType int
func ParseNaturalDate ¶ added in v0.0.4
ParseNaturalDate query string.
func (ExprType) IsDateOnly ¶ added in v0.0.4
func (ExprType) IsTimeOnly ¶ added in v0.0.4
type NepaliFormatter ¶ added in v0.0.4
type NepaliFormatter struct {
// contains filtered or unexported fields
}
func NewFormatter ¶ added in v0.0.4
func NewFormatter(nepaliTime *NepaliTime) *NepaliFormatter
type NepaliMonthData ¶ added in v0.0.4
type NepaliMonthData struct {
// contains filtered or unexported fields
}
type NepaliTime ¶ added in v0.0.4
type NepaliTime struct {
// contains filtered or unexported fields
}
func Date ¶ added in v0.0.4
func Date(year, month, day, hour, min, sec, nsec int) (*NepaliTime, error)
Date returns the Time corresponding to
yyyy-mm-dd hh:mm:ss + nsec nanoseconds
func FromEnglishTime ¶ added in v0.0.4
func FromEnglishTime(englishTime time.Time) (*NepaliTime, error)
Converts Time object to NepaliTime
func Now ¶ added in v0.0.4
func Now() *NepaliTime
Now returns the current nepali time. this function should always work and should not return nil in normal circumstances
func ParseNP ¶ added in v0.0.4
func ParseNP(datetimeStr string, format string) (*NepaliTime, error)
ParseNP equivalent to time.Parse()
func (*NepaliTime) Clock ¶ added in v0.0.4
func (obj *NepaliTime) Clock() (hour, min, sec int)
Clock returns the hour, minute, and second of the day.
func (*NepaliTime) Date ¶ added in v0.0.4
func (obj *NepaliTime) Date() (year, month, day int)
Date returns the year, month, and day
func (*NepaliTime) Day ¶ added in v0.0.4
func (obj *NepaliTime) Day() int
Day returns the day of the month.
func (*NepaliTime) Format ¶ added in v0.0.4
func (obj *NepaliTime) Format(format string) (string, error)
formats the nepalitime object into the passed format
func (*NepaliTime) GetEnglishTime ¶ added in v0.0.4
func (obj *NepaliTime) GetEnglishTime() time.Time
Get's the corresponding english time
func (*NepaliTime) Hour ¶ added in v0.0.4
func (obj *NepaliTime) Hour() int
Hour returns the hour within the day, in the range [0, 23].
func (*NepaliTime) Minute ¶ added in v0.0.4
func (obj *NepaliTime) Minute() int
Minute returns the minute offset within the hour, in the range [0, 59].
func (*NepaliTime) Month ¶ added in v0.0.4
func (obj *NepaliTime) Month() int
Month returns the month of the year.
func (*NepaliTime) Nanosecond ¶ added in v0.0.4
func (obj *NepaliTime) Nanosecond() int
Nanosecond returns the nanosecond offset within the second, in the range [0, 999999999].
func (*NepaliTime) Second ¶ added in v0.0.4
func (obj *NepaliTime) Second() int
Second returns the second offset within the minute, in the range [0, 59].
func (*NepaliTime) String ¶ added in v0.0.4
func (obj *NepaliTime) String() string
String returns a string representing the duration in the form "2079-10-06 01:00:05"
func (*NepaliTime) Weekday ¶ added in v0.0.4
func (obj *NepaliTime) Weekday() time.Weekday
Weekday returns the day of the week. Sunday = 0, Monday = 1, Saturday = 6
func (*NepaliTime) Year ¶ added in v0.0.4
func (obj *NepaliTime) Year() int
Year returns the year in which nepalitime occurs.
type Option ¶ added in v0.0.4
type Option func(*gparser)
Option function.
func WithDirection ¶ added in v0.0.4
WithDirection sets the direction used for ambiguous expressions. By default the Past direction is used, so "sunday" will be the previous Sunday, rather than the next Sunday.
type ParserOption ¶
type ParserOption func(*parser) error
ParserOption defines a function signature implemented by options Options defined like this accept the parser and operate on the data within
func AllowPartialStringMatch ¶
func AllowPartialStringMatch(allowPartialStringMatch bool) ParserOption
AllowPartialStringMatch is an option that allows allowPartialStringMatch to be changed from its default. If true, then strings can be attempted to be parsed / matched even if the end of the string might contain more than a date/time. This defaults to false.
func PreferMonthFirst ¶
func PreferMonthFirst(preferMonthFirst bool) ParserOption
PreferMonthFirst is an option that allows preferMonthFirst to be changed from its default
func RetryAmbiguousDateWithSwap ¶
func RetryAmbiguousDateWithSwap(retryAmbiguousDateWithSwap bool) ParserOption
RetryAmbiguousDateWithSwap is an option that allows retryAmbiguousDateWithSwap to be changed from its default
func SimpleErrorMessages ¶
func SimpleErrorMessages(simpleErrorMessages bool) ParserOption
SimpleErrorMessages is an option that will cause returned error messages to contain less detail, but it will avoid allocating any memory for the custom error message. If you expect to attempt to parse a lot of text that is not valid, this could help reduce GC pressure.