// JulianDayNumber reports the Julian Day Number for t. Note that Julian days
// start at 12:00 UTC.
519437
func JulianDayNumber(t time.Time) int {
	// algorithm from http://www.tondering.dk/claus/cal/julperiod.php#formula
	utc := t.UTC()
	a := (14 - int(utc.Month())) / 12
	y := utc.Year() + 4800 - a
	m := int(utc.Month()) + 12*a - 3

	jdn := utc.Day() + (153*m+2)/5 + 365*y + y/4 - y/100 + y/400 - 32045
	if utc.Hour() < 12 {
		jdn--
	}
	return jdn
}
621912
func parseDateTimeFromNum(num int64) (Time, error) {
	t := ZeroDate
	// Check zero.
	if num == 0 {
		return t, nil
	}

	// Check datetime type.
	if num >= 10000101000000 {
		return getTime(num, t.Type)
	}

	// Check MMDD.
	if num < 101 {
		return t, errors.Trace(ErrInvalidTimeFormat)
	}

	// Adjust year
	// YYMMDD, year: 2000-2069
	if num <= (70-1)*10000+1231 {
		num = (num + 20000000) * 1000000
		return getTime(num, t.Type)
	}

	// Check YYMMDD.
	if num < 70*10000+101 {
		return t, errors.Trace(ErrInvalidTimeFormat)
	}

	// Adjust year
	// YYMMDD, year: 1970-1999
	if num <= 991231 {
		num = (num + 19000000) * 1000000
		return getTime(num, t.Type)
	}

	// Check YYYYMMDD.
	if num < 10000101 {
		return t, errors.Trace(ErrInvalidTimeFormat)
	}

	// Adjust hour/min/second.
	if num <= 99991231 {
		num = num * 1000000
		return getTime(num, t.Type)
	}

	// Check MMDDHHMMSS.
	if num < 101000000 {
		return t, errors.Trace(ErrInvalidTimeFormat)
	}

	// Set TypeDatetime type.
	t.Type = mysql.TypeDatetime

	// Adjust year
	// YYMMDDHHMMSS, 2000-2069
	if num <= 69*10000000000+1231235959 {
		num = num + 20000000000000
		return getTime(num, t.Type)
	}

	// Check YYYYMMDDHHMMSS.
	if num < 70*10000000000+101000000 {
		return t, errors.Trace(ErrInvalidTimeFormat)
	}

	// Adjust year
	// YYMMDDHHMMSS, 1970-1999
	if num <= 991231235959 {
		num = num + 19000000000000
		return getTime(num, t.Type)
	}

	return getTime(num, t.Type)
}
67161
func BeginOf(t time.Time, unit UnitOfTime) time.Time {
	// Retrieve the individual parts of the given time.
	year := t.Year()
	month := t.Month()
	day := t.Day()
	hour := t.Hour()
	minute := t.Minute()
	second := t.Second()
	loc := t.Location()
	// Build new time.
	switch unit {
	case Second:
		return time.Date(year, month, day, hour, minute, second, 0, loc)
	case Minute:
		return time.Date(year, month, day, hour, minute, 0, 0, loc)
	case Hour:
		return time.Date(year, month, day, hour, 0, 0, 0, loc)
	case Day:
		return time.Date(year, month, day, 0, 0, 0, 0, loc)
	case Month:
		return time.Date(year, month, 1, 0, 0, 0, 0, loc)
	case Year:
		return time.Date(year, time.January, 1, 0, 0, 0, 0, loc)
	default:
		return t
	}
}
1311590
def julian_date(year, month=1, day=1, hour=0, minute=0, second=0.0):
    """"""
    return julian_day(year, month, day) - 0.5 + (
        second + minute * 60.0 + hour * 3600.0) / DAY_S
1196235
func (s *WeeklyAutoScalingSchedule) SetTuesday(v map[string]*string) *WeeklyAutoScalingSchedule {
	s.Tuesday = v
	return s
}
915273
func NewTimeBased() (UUID, error) {
	u, err := timebased.NewUUID()
	if err != nil {
		return Nil, err
	}

	uuid := UUID{}
	copy(uuid[:], u)

	return uuid, nil
}
1268740
func TimeOrderedUUID() string {
	unix := uint32(time.Now().UTC().Unix())

	b := make([]byte, 12)
	n, err := rand.Read(b)
	if n != len(b) {
		err = fmt.Errorf("Not enough entropy available")
	}
	if err != nil {
		panic(err)
	}
	return fmt.Sprintf("%08x-%04x-%04x-%04x-%04x%08x",
		unix, b[0:2], b[2:4], b[4:6], b[6:8], b[8:])
}
148472
func (t Time) ToNumber() *MyDecimal {
	if t.IsZero() {
		return &MyDecimal{}
	}

	// Fix issue #1046
	// Prevents from converting 2012-12-12 to 20121212000000
	var tfStr string
	if t.Type == mysql.TypeDate {
		tfStr = dateFormat
	} else {
		tfStr = numberFormat
	}

	s, err := t.DateFormat(tfStr)
	if err != nil {
		logutil.Logger(context.Background()).Error("[fatal] never happen because we've control the format!")
	}

	if t.Fsp > 0 {
		s1 := fmt.Sprintf("%s.%06d", s, t.Time.Microsecond())
		s = s1[:len(s)+t.Fsp+1]
	}

	// We skip checking error here because time formatted string can be parsed certainly.
	dec := new(MyDecimal)
	err = dec.FromString([]byte(s))
	terror.Log(errors.Trace(err))
	return dec
}
645820
func (s *RetentionPeriod) SetNumberOfDays(v int64) *RetentionPeriod {
	s.NumberOfDays = &v
	return s
}
367565
public static function jdDayOfWeek($julian_day, $mode)
    {
        $day_of_week = ($julian_day + 1) % 7;
        if ($day_of_week < 0) {
            $day_of_week += 7;
        }

        switch ($mode) {
            case 1: // 1, not CAL_DOW_LONG - see bug 67960
                return self::$DAY_NAMES[$day_of_week];

            case 2: // 2, not CAL_DOW_SHORT - see bug 67960
                return self::$DAY_NAMES_SHORT[$day_of_week];

            default: // CAL_DOW_DAYNO or anything else
                return $day_of_week;
        }
    }
421039
func Date() time.Time {
	return time.Date(Year(), time.Month(Number(0, 12)), Day(), Hour(), Minute(), Second(), NanoSecond(), time.UTC)
}
281842
def julian_day(t: date) -> int:
    """"""
    # Compute the number of days from January 1, 2000 to date t
    dt = t - julian_base_date
    # Add the julian base number to the number of days from the julian base date to date t
    return julian_base_number + dt.days
398874
func calcJulianCentury(julianDay []float64) (julianCentury []float64) {
	for index := 0; index < len(julianDay); index++ {
		temp := (julianDay[index] - 2451545.0) / 36525.0
		julianCentury = append(julianCentury, temp)
	}
	return
}
621124
func (c Calendar) formatDateTimeComponentDay(datetime time.Time, length int) (string, error) {
	day := datetime.Day()

	switch length {
	case datetimeFormatLength1Plus:
		return fmt.Sprintf("%d", day), nil
	case datetimeFormatLength2Plus:
		if day < 10 {
			return fmt.Sprintf("0%d", day), nil
		}
		return fmt.Sprintf("%d", day), nil
	}

	return "", fmt.Errorf("unsupported day-of-year: %d", length)
}
763914
func Date(ti int64, format string) string {
	t := time.Unix(int64(ti), 0)
	return DateT(t, format)
}
781916
public function jdToYmd($julian_day)
    {
        // Find the year, by adding one month at a time to use up the remaining days.
        $year  = $this->jdToY($julian_day);
        $month = 1;
        $day   = $julian_day - $this->yToJd($year) + 1;

        while ($day > $this->daysInMonth($year, $month)) {
            $day -= $this->daysInMonth($year, $month);
            $month++;
        }

        // PHP 5.4 and earlier converted non leap-year Adar into month 6, instead of month 7.
        $month -= ($month === 7 && $this->options[self::EMULATE_BUG_54254] && !$this->isLeapYear($year)) ? 1 : 0;

        return array($year, $month, $day);
    }
184713
func (t *Translator) formatDateTimeComponentDay(datetime time.Time, length int) (string, error) {
	day := datetime.Day()

	switch length {
	case datetimeFormatLength1Plus:
		return fmt.Sprintf("%d", day), nil
	case datetimeFormatLength2Plus:
		if day < 10 {
			return fmt.Sprintf("0%d", day), nil
		}
		return fmt.Sprintf("%d", day), nil
	}

	return "", translatorError{message: fmt.Sprintf("unsupported day-of-year: %d", length)}
}