diff options
| author | Shulhan <ms@kilabit.info> | 2023-12-17 12:21:04 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-12-17 13:35:34 +0700 |
| commit | 74ab6e619e4a93efe4b5c092d843c58c731147bb (patch) | |
| tree | 3f314c52199f6f171933cef54ef4683684101afb | |
| parent | f6e42394855867023fb80f30d4b6059a5d7c2ba9 (diff) | |
| download | pakakeh.go-74ab6e619e4a93efe4b5c092d843c58c731147bb.tar.xz | |
lib/time: remove UnixMicro and UnixMilli
Both of those methods has been added into standard library as
[Time.UnixMicro] and [Time.UnixMilli] since Go 1.17.
| -rw-r--r-- | lib/time/time.go | 17 | ||||
| -rw-r--r-- | lib/time/time_example_test.go | 14 |
2 files changed, 2 insertions, 29 deletions
diff --git a/lib/time/time.go b/lib/time/time.go index afb7d0f3..1748a4f9 100644 --- a/lib/time/time.go +++ b/lib/time/time.go @@ -41,26 +41,13 @@ var ShortMonths = map[string]time.Month{ // For example, if the unix nano seconds is 1612331218913557000 then the micro // second value is 913557. // -// To get the unix microsecond use UnixMicro(). +// To get the unix microsecond use [time.Time.UnixMicro]. func Microsecond(t *time.Time) int64 { seconds := t.Unix() * int64(time.Second) return (t.UnixNano() - seconds) / int64(time.Microsecond) } -// UnixMicro returns t as a Unix time in microsecond. -// For example, if the unix nano seconds is 1612331218913557000 then the -// UnixMicro value is 1612331218913557. -func UnixMicro(t *time.Time) int64 { - return t.UnixNano() / int64(time.Microsecond) -} - -// UnixMilli returns t as a Unix time, the number of milliseconds elapsed -// since January 1, 1970 UTC. -func UnixMilli(t time.Time) int64 { - return t.UnixNano() / int64(time.Millisecond) -} - // UnixMilliString returns the UnixMilli() as string. func UnixMilliString(t time.Time) string { - return strconv.FormatInt(UnixMilli(t), 10) + return strconv.FormatInt(t.UnixMilli(), 10) } diff --git a/lib/time/time_example_test.go b/lib/time/time_example_test.go index 7261d198..c0926ec1 100644 --- a/lib/time/time_example_test.go +++ b/lib/time/time_example_test.go @@ -16,20 +16,6 @@ func ExampleMicrosecond() { //123456 } -func ExampleUnixMicro() { - nano := time.Unix(1612331000, 123456789) - fmt.Printf("%d", UnixMicro(&nano)) - //Output: - //1612331000123456 -} - -func ExampleUnixMilli() { - nano := time.Unix(1612331000, 123456789) - fmt.Printf("%d", UnixMilli(nano)) - //Output: - //1612331000123 -} - func ExampleUnixMilliString() { nano := time.Unix(1612331000, 123456789) fmt.Printf("%s", UnixMilliString(nano)) |
