package mhayaTime

import (
	"time"

	cstring "github.com/mhaya/extend/string"
)

// ToSecond 输出秒级时间戳
func (c MhayaTime) ToSecond() int64 {
	return c.Unix()
}

// ToMillisecond 输出毫秒级时间戳
func (c MhayaTime) ToMillisecond() int64 {
	return c.Time.UnixNano() / int64(time.Millisecond)
}

func (c MhayaTime) ToMillisecondString() string {
	t := c.ToMillisecond()
	return cstring.ToString(t)
}

// ToMicrosecond 输出微秒级时间戳
func (c MhayaTime) ToMicrosecond() int64 {
	return c.UnixNano() / int64(time.Microsecond)
}

// ToNanosecond 输出纳秒级时间戳
func (c MhayaTime) ToNanosecond() int64 {
	return c.UnixNano()
}

// ToDateMillisecondFormat 2023-04-10 12:26:57.420
func (c MhayaTime) ToDateMillisecondFormat() string {
	return c.Format(DateTimeMillisecondFormat)
}

// ToDateTimeFormat 2006-01-02 15:04:05
func (c MhayaTime) ToDateTimeFormat() string {
	return c.Format(DateTimeFormat)
}

// ToDateFormat 2006-01-02
func (c MhayaTime) ToDateFormat() string {
	return c.Format(DateFormat)
}

// ToTimeFormat 15:04:05
func (c MhayaTime) ToTimeFormat() string {
	return c.Format(TimeFormat)
}

// ToShortDateTimeFormat 20060102150405
func (c MhayaTime) ToShortDateTimeFormat() string {
	return c.Format(ShortDateTimeFormat)
}

// ToShortDateFormat 20060102
func (c MhayaTime) ToShortDateFormat() string {
	return c.Format(ShortDateFormat)
}

// ToShortIntDateFormat 20060102
func (c MhayaTime) ToShortIntDateFormat() int32 {
	strDate := c.ToShortDateFormat()
	intDate, _ := cstring.ToInt32(strDate)
	return intDate
}

// ToShortTimeFormat 150405
func (c MhayaTime) ToShortTimeFormat() string {
	return c.Format(ShortTimeFormat)
}

func (c MhayaTime) DailyTOTimeStamp() int64 {
	now := Now()
	t := time.Date(now.Year(), time.Month(now.Month()), now.Day(), 0, 0, 0, 0, now.Location())
	return t.Unix()
}

func (c MhayaTime) TOTimeStamp() int64 {
	t := time.Date(c.Year(), time.Month(c.Month()), c.Day(), 0, 0, 0, 0, c.Location())
	return t.Unix()
}

func (c MhayaTime) TOHourTimeStamp() int64 {
	t := time.Date(c.Year(), time.Month(c.Month()), c.Day(), c.Hour(), 0, 0, 0, c.Location())
	return t.Unix()
}
