Contains primitives for marshaling/unmarshaling Unix timestamp/epoch to/from built-in time.Time type in JSON

epoch

Mentioned in Awesome Go Godoc Reference build codecov goreportcard

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"}
Owner
Vilen Topchii
ʕ◔ϖ◔ʔ
Vilen Topchii
Similar Resources

A simple command line -based snake game built with go and termbox

A simple command line -based snake game built with go and termbox

snake-task Snake Game A simple command line -based snake game built with go and termbox library. This is a test task for a Golang positon. It took me

Jan 16, 2022

A Lambda function built with SAM (Serverless Application Module)

AWS SAM Lambda Function © Israel Pereira Tavares da Silva The AWS Serverless Application Model (SAM) is an open-source framework for building serverle

Dec 19, 2021

A simple api built in Go that facilitates directly sending email from your client side html to your inbox

go-email-service A simple api built in Go that facilitates directly sending emai

Dec 28, 2021

An app/container built in Go to automate a Twitter account using Notion

Notion Tweeter Notion Tweeter is a utility I built using Go to help automate scheduling my tweets using Notion as a backend. More documentation coming

Sep 26, 2022

Simple CRUD API written in Go, built using AWS SAM tool and using the AWS' infrastructure.

Simple CRUD API written in Go, built using AWS SAM tool and using the AWS' infrastructure.

tutor-pet API Simple CRUD API written in Go, built using AWS SAM tool and using the AWS' infrastructure. Macro architecture: Code architecture: Pre-Re

Aug 17, 2022

Komikuapitk - Restful API Manga bahasa Indonesia built with Go

Komikku API Restful API Manga bahasa Indonesia built with ❤️ and Go Usage Clone

Sep 2, 2022

Nvote - Decentralized, vote-driven community similar to services like Reddit and HackerNews. Built on nostr

NVote Nvote is a decentralized, vote-driven community similar to services like R

Jan 4, 2023

A simple OpenWeather API client built in Go for learning purpose.

OpenWeather client A simple OpenWeather API client built in Go for learning purpose

May 1, 2022

Golang client for ethereum json rpc api

Ethrpc Golang client for ethereum JSON RPC API. web3_clientVersion web3_sha3 net_version net_peerCount net_listening eth_protocolVersion eth_syncing e

Jan 7, 2023
Comments
  • Switch to UnixMilli funcs (Go 1.17)

    Switch to UnixMilli funcs (Go 1.17)

    https://pkg.go.dev/time#Time.UnixMilli and https://pkg.go.dev/time#UnixMilli


    Get rid of https://pkg.go.dev/time#Time.UnixNano

    The result is undefined if the Unix time in nanoseconds cannot be represented by an int64 (a date before the year 1678 or after 2262). Note that this means the result of calling UnixNano on the zero Time is undefined.

gofrrsockets is a client library used to interact with FRR's daemon UNIX sockets

gofrrsockets gofrrsockets is a client library that can be used to send commands to FRR's daemon UNIX sockets. The library provides a safer (forking cm

Jun 13, 2022
G-array is a GoLang library, that contains the generic function to do the array operations.

G-array Garray is a library written in Go (Golang). Which have a collection of functions to do the array operations. Installation To install G-array p

Oct 3, 2022
This library implements the pub/sub pattern in a generic way. It uses Go's generic types to declare the type of the event.

observer This library implements the pub/sub pattern in a generic way. It uses Go's generic types to declare the type of the event. Usage go get githu

Nov 16, 2022
twitter clone front-end for Internet Engineering course - fall 99 built by go+echo

twitter backend build twitter-like back-end for internet engeering course - fall 99 with go+echo+gorm team mates Roozbeh Sharifnasab + Parsa Fadaee +

Nov 9, 2022
A serverless sync server for Santa, built on AWS

Rudolph Rudolph is the control server counterpart of Santa, and is used to rapidly deploy configurations to Santa agents. Rudolph is built in Amazon W

Dec 5, 2022
Run proprietary modpack in built in Darwin/macOS sandbox-exec to prevent it from doing malicious things.
Run proprietary modpack in built in Darwin/macOS sandbox-exec to prevent it from doing malicious things.

sandbox-exec lunarclient Run LunarClient in built in Darwin/macOS sandbox-exec to prevent lunar from taking screenshots of your desktop. LunarClient l

Jul 12, 2022
go-macos-pkg was built out of a desire to generate and sign macOS pkgs on non-macOS OSs.

About go-macos-pkg was built out of a desire to generate and sign macOS pkgs on non-macOS OSs. Caveats Right now most of the heavy lifting is done by

Aug 18, 2022
planet is a blockchain built using Cosmos SDK and Tendermint and created with Starport.

planet planet is a blockchain built using Cosmos SDK and Tendermint and created with Starport. Get started starport chain serve serve command install

Oct 31, 2021
A decentralized vinyl marketplace demo built with Go, Cosmos SDK and Starport

emusicchain emusicchain is a blockchain built using Cosmos SDK and Tendermint and created with Starport. Get started starport chain serve serve comma

Dec 5, 2021
A very simple local client-server calculator project built using Cobra and socket programming, written in Go.

Golculator Introduction A very simple local client-server calculator project built using Cobra and socket programming, written in Go. Setup and run Fi

Apr 3, 2022