// returns days since Jan 1st 0001 in Gregorian calendar
426046
func gregorianDays(year, yearday int) int {
	year0 := year - 1
	return year0*365 + year0/4 - year0/100 + year0/400 + yearday - 1
}
986064
func DateLess(i *google_type.Date, j *google_type.Date) bool {
	if j == nil {
		return false
	}
	if i == nil {
		return true
	}
	if i.Year < j.Year {
		return true
	}
	if i.Year > j.Year {
		return false
	}
	if i.Month < j.Month {
		return true
	}
	if i.Month > j.Month {
		return false
	}
	return i.Day < j.Day
}
220631
func (c *Carbon) DiffInWeekendDays(carb *Carbon, abs bool) int64 {
	f := func(t *Carbon) bool {
		return t.IsWeekend()
	}

	return c.DiffFiltered(dayDuration, f, carb, abs)
}
720341
func ISO8601(date interface{}, optArgs ...ISO8601Opts) Term {

	opts := map[string]interface{}{}
	if len(optArgs) >= 1 {
		opts = optArgs[0].toMap()
	}
	return constructRootTerm("ISO8601", p.Term_ISO8601, []interface{}{date}, opts)
}
1077361
func (n NullDate) Ptr() *Date {
	if n.Valid {
		v := n.Date
		return &v
	}
	return nil
}
750498
func SameDay(left time.Time, right time.Time) bool {
	return left.Year() == right.Year() && left.Month() == right.Month() && left.Day() == right.Day()
}
328716
func DateS(ts string, format string) string {
	i, _ := strconv.ParseInt(ts, 10, 64)
	return Date(i, format)
}
498678
func MonthDays(year, month int) int {
	switch month {
	case 1, 3, 5, 7, 8, 10, 12:
		return 31
	case 4, 6, 9, 11:
		return 30
	case 2:
		if IsLeapYear(year) {
			return 29
		}
		return 28
	default:
		panic(fmt.Sprintf("Illegal month:%d", month))
	}
}
912104
func DateFor(year int, month time.Month, day int) Date {
	return Date{
		t: time.Date(year, month, day, 0, 0, 0, 0, time.UTC),
	}
}
750138
func FromDate(year int, month int, day int, hour int, minute int, second int, microsecond int) TimeInternal {
	return newMysqlTime(year, month, day, hour, minute, second, microsecond)
}
737857
func NewCalendar() *Calendar {
	c := &Calendar{}
	for i := range c.holidays {
		c.holidays[i] = make([]Holiday, 0, 2)
	}
	c.workday[time.Monday] = true
	c.workday[time.Tuesday] = true
	c.workday[time.Wednesday] = true
	c.workday[time.Thursday] = true
	c.workday[time.Friday] = true
	return c
}
56093
func (h *Holiday) matches(date time.Time) bool {

	if h.Func != nil && (date.Year() != h.lastYear || date.Location() != h.lastLoc) {
		h.Month, h.Day = h.Func(date.Year(), date.Location())
		h.lastYear = date.Year()
		h.lastLoc = date.Location()
	}

	if h.Month > 0 {
		if date.Month() != h.Month {
			return false
		}
		if h.Year > 0 && date.Year() != h.Year {
			return false
		}
		if h.Day > 0 {
			return date.Day() == h.Day
		}
		if h.Weekday > 0 && h.Offset != 0 {
			return IsWeekdayN(date, h.Weekday, h.Offset)
		}
	} else if h.Offset > 0 {
		return date.YearDay() == h.Offset
	}
	return false
}
931815
func (t Term) DayOfYear(args ...interface{}) Term {
	return constructMethodTerm(t, "DayOfYear", p.Term_DAY_OF_YEAR, args, map[string]interface{}{})
}
111887
func UnmarshalTimeOfDay(s string) (TimeOfDay, error) {
	t, err := UnmarshalTimeOfDayTz(s)
	if err != nil {
		return TimeOfDay{}, err
	} else if t.HasOffset {
		return TimeOfDay{}, fmt.Errorf("soap time: value %q contains unexpected timezone", s)
	}
	return t, nil
}
382935
func (c *CommitAuthor) GetDate() time.Time {
	if c == nil || c.Date == nil {
		return time.Time{}
	}
	return *c.Date
}
116197
func toDays(duration time.Duration) time.Duration {
	days := duration.Nanoseconds() / nanosecondsPerDay
	nanoseconds := days * nanosecondsPerDay
	return time.Duration(nanoseconds)
}
833751
func (d Date) String() string {
	return fmt.Sprintf(dateFormat, d.Year(), d.Month(), d.Day())
}