pkg.re/essentialkaos/ek.10@v12.41.0+incompatible/timeutil/tinydate.go (about) 1 package timeutil 2 3 // ////////////////////////////////////////////////////////////////////////////////// // 4 // // 5 // Copyright (c) 2022 ESSENTIAL KAOS // 6 // Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> // 7 // // 8 // ////////////////////////////////////////////////////////////////////////////////// // 9 10 import ( 11 "time" 12 ) 13 14 // ////////////////////////////////////////////////////////////////////////////////// // 15 16 // Date is tiny date 17 type Date uint32 18 19 // ////////////////////////////////////////////////////////////////////////////////// // 20 21 // StartDate contains start date timestamp 22 var StartDate = uint32(1322611200) 23 24 // ////////////////////////////////////////////////////////////////////////////////// // 25 26 // TinyDate creates tiny date struct by timestamp 27 func TinyDate(t int64) Date { 28 return Date(uint32(t) - StartDate) 29 } 30 31 // Unix returns unix timestamp 32 func (d Date) Unix() int64 { 33 return int64(StartDate + uint32(d)) 34 } 35 36 // Time returns time struct 37 func (d Date) Time() time.Time { 38 return time.Unix(int64(uint32(d)+StartDate), 0) 39 }