Epoch
Contains primitives for marshaling/unmarshaling Unix timestamp/epoch to/from built-in time.Time type in JSON
Install / Use
/learn @vtopc/EpochREADME
epoch
Contains primitives for marshaling/unmarshaling Unix timestamp/epoch to/from built-in time.Time type in JSON.
Seconds
Seconds since the Epoch(Unix time), e.g.:
{"timestamp":1136239445}
Inherits built-in time.Time type, thus has all it methods, but has custom serializer and deserializer(converts integer into built-in time.Time and vice versa).
Usage Example
package main
import (
"encoding/json"
"fmt"
"github.com/vtopc/epoch"
)
type Request struct {
Timestamp epoch.Seconds `json:"timestamp"`
}
func main() {
var v Request
err := json.Unmarshal([]byte(`{"timestamp":1136239445}`), &v)
if err != nil {
panic(err)
}
fmt.Printf("%+v\n", v)
// Output: {Timestamp:2006-01-03 00:04:05 +0200 EET}
// Also as epoch.Seconds inherits all time.Time's methods one can do next:
fmt.Println(v.Timestamp.Year())
// Output: 2006
fmt.Println(v.Timestamp.UTC().String())
// Output: 2006-01-02 22:04:05 +0000 UTC
}
Milliseconds
Same as epoch.Seconds, but for Epoch(Unix time) in milliseconds, e.g.:
{"timestamp":1136239445999}
StrSeconds
Same as epoch.Seconds, but for strings, e.g.:
{"timestamp":"1136239445"}
StrMilliseconds
Same as epoch.Milliseconds, but for strings, e.g.:
{"timestamp":"1136239445999"}
FloatMS
Integer part of timestamp represents seconds and fractional - milliseconds since the Epoch(Unix time), e.g.:
{"timestamp":1136239445.999}
Installation
go get github.com/vtopc/epoch@latest
This will update yours go.mod file.
Additional terms of use for users from russia and Belarus
By using the code provided in these repositories you agree with the following:
- russia has illegally annexed Crimea in 2014 and brought the war in Donbas followed by full-scale invasion of Ukraine in 2022.
- russia has brought sorrow and devastations to millions of Ukrainians, killed hundreds of innocent people, damaged thousands of buildings, and forced several million people to flee.
- Putin khuylo!
Glory to Ukraine! 🇺🇦
Related Skills
bluebubbles
346.8kUse when you need to send or manage iMessages via BlueBubbles (recommended iMessage integration). Calls go through the generic message tool with channel="bluebubbles".
gh-issues
346.8kFetch GitHub issues, spawn sub-agents to implement fixes and open PRs, then monitor and address PR review comments. Usage: /gh-issues [owner/repo] [--label bug] [--limit 5] [--milestone v1.0] [--assignee @me] [--fork user/repo] [--watch] [--interval 5] [--reviews-only] [--cron] [--dry-run] [--model glm-5] [--notify-channel -1002381931352]
healthcheck
346.8kHost security hardening and risk-tolerance configuration for OpenClaw deployments
node-connect
346.8kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
