A go implementation of smalltime.
Smalltime is a simple and convenient binary date & time format in 64 bits.
- Encodes a complete date & time into a 64-bit signed integer.
- Fields (including year) are compatible with ISO-8601.
- Maintenance-free (no leap second tables to update).
- Easily converts to human readable fields.
- Supports hundreds of thousands of years.
- Supports time units to the microsecond.
- Supports leap years and leap seconds.
- Encoded values are comparable.
import "fmt"
import "github.com/kstenerud/go-smalltime"
func demonstrateSmalltime() {
noonJan12000 := smalltime.New(2000, 1, 1, 12, 0, 0, 0)
oneOclockJan12000 := smalltime.New(2000, 1, 1, 13, 0, 0, 0)
feb151999 := smalltime.New(1999, 2, 15, 12, 8, 45, 9122)
if oneOclockJan12000 > noonJan12000 {
fmt.Printf("Comparison: One o'clock is greater than noon.\n")
}
if feb151999 < noonJan12000 {
fmt.Printf("Comparison: Feb 15, 1999 is less than Jan 1, 2000.\n")
}
gotime := feb151999.AsTime()
fmt.Printf("Go Time: %v\n", gotime)
smtime := smalltime.FromTime(gotime)
fmt.Printf("Smalltime Raw: 0x%016x\n", smtime)
fmt.Printf("Smalltime Fields: %04d-%02d-%02d %02d:%02d:%02d.%06d\n",
smtime.Year(), smtime.Month(), smtime.Day(), smtime.Hour(),
smtime.Minute(), smtime.Second(), smtime.Microsecond())
}
Output:
Comparison: One o'clock is greater than noon.
Comparison: Feb 15, 1999 is less than Jan 1, 2000.
Go Time: 1999-02-15 12:08:45.009122 +0000 UTC
Smalltime Raw: 0x01f3c9ec22d023a2
Smalltime Fields: 1999-02-15 12:08:45.009122