Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vtopc/epoch
Contains primitives for marshaling/unmarshaling Unix timestamp/epoch to/from built-in time.Time type in JSON
https://github.com/vtopc/epoch
date deserialization epoch epoch-time go golang json rest rest-api rest-client rest-server restapi restful restful-api restful-webservices serialization time timestamp unix-timestamp
Last synced: 14 days ago
JSON representation
Contains primitives for marshaling/unmarshaling Unix timestamp/epoch to/from built-in time.Time type in JSON
- Host: GitHub
- URL: https://github.com/vtopc/epoch
- Owner: vtopc
- License: mit
- Created: 2019-12-15T12:54:37.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-02-25T14:22:45.000Z (9 months ago)
- Last Synced: 2024-07-30T20:43:28.782Z (3 months ago)
- Topics: date, deserialization, epoch, epoch-time, go, golang, json, rest, rest-api, rest-client, rest-server, restapi, restful, restful-api, restful-webservices, serialization, time, timestamp, unix-timestamp
- Language: Go
- Homepage:
- Size: 730 KB
- Stars: 14
- Watchers: 1
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - epoch - Contains primitives for marshaling/unmarshalling Unix timestamp/epoch to/from build-in time.Time type in JSON. (JSON / Search and Analytic Databases)
- awesome-go-extra - epoch - in time.Time type in JSON|9|3|1|2019-12-15T12:54:37Z|2022-05-18T20:47:51Z| (JSON / Advanced Console UIs)
README
[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner-direct-single.svg)](https://vshymanskyy.github.io/StandWithUkraine)
# epoch
[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)
[![Godoc Reference][godoc-img]][godoc-url] [![build][build-img]][build-url]
[![codecov][codecov-img]][codecov-url] [![goreportcard][goreportcard-img]][goreportcard-url]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.:
```json
{"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
```go
package mainimport (
"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.:
```json
{"timestamp":1136239445999}
```## StrSeconds
Same as epoch.Seconds, but for strings, e.g.:
```json
{"timestamp":"1136239445"}
```## StrMilliseconds
Same as epoch.Milliseconds, but for strings, e.g.:
```json
{"timestamp":"1136239445999"}
```## FloatMS
Integer part of timestamp represents seconds and fractional - milliseconds since the Epoch(Unix time),
e.g.:
```json
{"timestamp":1136239445.999}
```## Installation
```shell
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](https://en.wikipedia.org/wiki/Annexation_of_Crimea_by_the_Russian_Federation) and [brought the war in Donbas](https://en.wikipedia.org/wiki/War_in_Donbas) followed by [full-scale invasion of Ukraine in 2022](https://en.wikipedia.org/wiki/2022_Russian_invasion_of_Ukraine).
* 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!](https://en.wikipedia.org/wiki/Putin_khuylo!)Glory to Ukraine! πΊπ¦
[godoc-img]: https://godoc.org/github.com/vtopc/epoch?status.svg
[godoc-url]: https://godoc.org/github.com/vtopc/epoch[build-img]: https://github.com/vtopc/epoch/workflows/build/badge.svg
[build-url]: https://github.com/vtopc/epoch/actions?query=workflow%3A%22build%22[codecov-img]: https://codecov.io/gh/vtopc/epoch/branch/master/graph/badge.svg
[codecov-url]: https://codecov.io/gh/vtopc/epoch[goreportcard-img]: https://goreportcard.com/badge/github.com/vtopc/epoch
[goreportcard-url]: https://goreportcard.com/report/github.com/vtopc/epoch