Time struct in Go that uses 4 bytes of memory vs the 24 bytes of time.Time

Overview

go-tinytime

A tiny time object in Go. Tinytime uses 4 bytes of memory vs the 24 bytes of a standard time.Time{}

A tinytime only supports dates from 1970 to 2106. It uses a unix timestamp as a uint32.

βš™οΈ Installation

go get github.com/wagslane/go-tinytime

πŸš€ Quick Start

package main

import (
    tinytime "github.com/wagslane/go-tinytime"
)

func main(){
    tt, err := tinytime.New(1585750374)
	if err != nil {
		fmt.Println(err.Error())
    }
    
    tt = tt.Add(time.Hour * 48)
    fmt.Println(tt)
    // prints 2020-04-05
}

Need More Date Ranges? Go-TinyDate

Unix timestamps only supports dates from 1970 to 2106. If you need a larger date range, take a look at go-tinydate which uses day-month-year underneath. Keep in mind go-tinydate doesn't support more than day precision.

Why?

If you don't have resource constraints, then don't use tinytime! Use the standard time pacakge.

go-tinytime works well in the following situations:

  • You are working in embedded systems where memory is a luxury
  • You are storing many dates and smaller memory footprint is desired
  • You are 101% sure you don't need a date range larger than 1970-2106

πŸ’¬ Contact

Twitter Follow

Submit an issue (above in the issues tab)

API

Godoc: https://godoc.org/github.com/wagslane/go-tinytime

Tinytime mirrors the time.Time API for the most part. The only methods that are not included are the ones that makes no sense without timezone support.

Formatting

All formatting is done via the time.Time package's formatting capabilites.

Transient Dependencies

None! And it will stay that way, except of course for the standard library.

Note: Currently the testify package is used only for testing, but that dependency will be removed in coming updates.

πŸ‘ Contributing

I love help! Contribute by forking the repo and opening pull requests. Please ensure that your code passes the existing tests and linting, and write tests to test your changes if applicable.

All pull requests should be submitted to the "master" branch.

go test
go fmt
You might also like...
Copy of stdlib's time.Duration, but ParseDuration accepts other bigger units such as days, weeks, months and years

duration Copy of stdlib's time.Duration, but ParseDuration accepts other units as well: d: days (7 * 24 * time.Hour) w: weeks (7 * Day) mo: months (30

time format golang

a simple plugin to change date and time format

Structural time package for jalali calendar

Jalali Structural time package for jalali calendar. This package support parse from string, json and time. Structures There are three data structures

Show time by timezone

Show time by timezone

Timediff is a Go package for printing human readable, relative time differences πŸ•°οΈ

timediff is a Go package for printing human readable, relative time differences. Output is based on ranges defined in the Day.js JavaScript library, and can be customized if needed.

Go-timeparser - Flexible Time Parser for Golang

go-timeparser Flexible Time Parser for Golang Installation Download timeparser w

A tiny date object in Go. Tinydate uses only 4 bytes of memory

go-tinydate A tiny date object in Go. Tinydate uses 4 bytes of memory vs the 24 bytes of a standard time.Time{} A tinydate only has day precision. It

goconfig uses a struct as input and populates the fields of this struct with parameters from command line, environment variables and configuration file.

goconfig goconfig uses a struct as input and populates the fields of this struct with parameters from command line, environment variables and configur

β˜„ The golang convenient converter supports Database to Struct, SQL to Struct, and JSON to Struct.
β˜„ The golang convenient converter supports Database to Struct, SQL to Struct, and JSON to Struct.

Gormat - Cross platform gopher tool The golang convenient converter supports Database to Struct, SQL to Struct, and JSON to Struct. δΈ­ζ–‡θ―΄ζ˜Ž Features Data

Memory-Alignment: a tool to help analyze layout of fields in struct in memory
Memory-Alignment: a tool to help analyze layout of fields in struct in memory

Memory Alignment Memory-Alignment is a tool to help analyze layout of fields in struct in memory. Usage go get github.com/vearne/mem-aligin Example p

RBTI Golang Server uses PostgreSQL and for its main database and uses Elasticsearch

RBTI Golang Server This server is used for my thesis project, it uses PostgreSQL and for its main database and uses Elasticsearch for faster query spe

Pagser is a simple, extensible, configurable parse and deserialize html page to struct based on goquery and struct tags for golang crawler
Pagser is a simple, extensible, configurable parse and deserialize html page to struct based on goquery and struct tags for golang crawler

Pagser Pagser inspired by page parser。 Pagser is a simple, extensible, configurable parse and deserialize html page to struct based on goquery and str

Match regex group into go struct using struct tags and automatic parsing

regroup Simple library to match regex expression named groups into go struct using struct tags and automatic parsing Installing go get github.com/oris

:100:Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and Array diving

Package validator Package validator implements value validations for structs and individual fields based on tags. It has the following unique features

Copier for golang, copy value from struct to struct and more

Copier I am a copier, I copy everything from one to another Features Copy from field to field with same name Copy from method to field with same name

πŸ’― Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and Array diving

Package validator implements value validations for structs and individual fields based on tags.

Go generator to copy values from type to type and fields from struct to struct. Copier without reflection.

Copygen is a command-line code generator that generates type-to-type and field-to-field struct code without adding any reflection or dependenc

Speed up the memory allocation and improve the GC performance, especially for dynamic-memory-heavy applications.
Speed up the memory allocation and improve the GC performance, especially for dynamic-memory-heavy applications.

Linear Allocator for Golang Goal Speed up the memory allocation and improve the GC performance, especially for dynamic-memory-heavy applications. Pote

gpu-memory-monitor is a metrics server for collecting GPU memory usage of kubernetes pods.

gpu-memory-monitor is a metrics server for collecting GPU memory usage of kubernetes pods. If you have a GPU machine, and some pods are using the GPU device, you can run the container by docker or kubernetes when your GPU device belongs to nvidia. The gpu-memory-monitor will collect the GPU memory usage of pods, you can get those metrics by API of gpu-memory-monitor

Owner
Lane Wagner
I like Go and Rust, and I tolerate JavaScript and Python. @wagslane on twitter.
Lane Wagner
:clock8: Better time duration formatting in Go!

durafmt durafmt is a tiny Go library that formats time.Duration strings (and types) into a human readable format. go get github.com/hako/durafmt Why

Wesley Hill 453 Dec 16, 2022
:clock1: Date and Time - Golang Formatting Library

Kair Date and Time - Golang Formatting Library Setup To get Kair > Go CLI go get github.com/GuilhermeCaruso/kair > Go DEP dep ensure -add github.com/G

Guilherme Caruso 24 Sep 26, 2022
Now is a time toolkit for golang

Now Now is a time toolkit for golang Install go get -u github.com/jinzhu/now Usage Calculating time based on current time import "github.com/jinzhu/n

Jinzhu 4k Dec 23, 2022
Golang package to manipulate time intervals.

timespan timespan is a Go library for interacting with intervals of time, defined as a start time and a duration. Documentation API Installation Insta

null 82 Sep 26, 2022
timeutil - useful extensions (Timedelta, Strftime, ...) to the golang's time package

timeutil - useful extensions to the golang's time package timeutil provides useful extensions (Timedelta, Strftime, ...) to the golang's time package.

Kyoung-chan Lee 190 Dec 22, 2022
Go time library inspired by Moment.js

Goment Current Version: 1.4.0 Changelog Goment is a port of the popular Javascript datetime library Moment.js. It follows the Moment.js API closely, w

Nick Leeper 209 Dec 24, 2022
fasttime - fast time formatting for go

fasttime - fast time formatting for go

phuslu 67 Dec 13, 2022
🌐 A time zone helper

?? A time zone helper tz helps you schedule things across time zones. It is an interactive TUI program that displays time across a few time zones of y

Arnaud Berthomier 703 Dec 29, 2022
Clock is a small library for mocking time in Go.

clock Clock is a small library for mocking time in Go. It provides an interface around the standard library's time package so that the application can

Ben Johnson 606 Dec 30, 2022
A natural language date/time parser with pluggable rules

when when is a natural language date/time parser with pluggable rules and merge strategies Examples tonight at 11:10 pm at Friday afternoon the deadli

Oleg Lebedev 1.2k Dec 26, 2022