Go's missing DateTime package

Overview

dt

Go's missing DateTime package

Build Status codecov Go Report Card

Why dt?

Go's standard library contains a single date package - time. The type provided by it, Time, contains date, time and location information.

More often than not we don't need location info, or we need to represent date/time only.

dt provides exactly that, a time-zone-independent representation of time that follows the rules of the proleptic Gregorian calendar with exactly 24-hour days, 60-minute hours, and 60-second minutes.

What is provided?

dt provides three types to work with:

  • Time: Contains time info: HH:mm
  • Date: Contains date info: YYYY-MM-DD
  • DateTime: Contains date and time information: YYYY-MM-DDTHH:mm

Unlike time.Time these types contain an additional Valid field representing whether the data inside it was scanned/marshaled. This prevents situations like saving default date in a database when nothing was received or responding via JSON with default date even though the date was empty.

Types provided in dt represent sql types time, date and timestamp.

Why not civil package?

Google already offers something similar in civil package.

  • It's not an independent library, but a small package in a very big project which leads to its problems.
  • It doesn't implement the Scan/Value SQL interfaces.
  • It marshalls to zero date/time/datetime (time.Time does this as well.) You can't differentiate inputted zero date/time/datetime and empty value.
  • Slower development cycle

License

dt is licensed under the Apache2 license. Check the LICENSE file for details.

Author

Emir Ribic

You might also like...
The missing package manager for golang binaries (its homebrew for "go install")

Bingo: The missing package manager for golang binaries (its homebrew for "go install") Do you love the simplicity of being able to download & compile

Errr - Errr (The Rich Structured Error Package missing from Go)

The errr package was created to fill the gap between error handling and error reporting.

All the missing AMD64 atomic instructions

atomics All the AMD64 atomic instructions, exposed as Go functions: ⚠️ PRE-ALPHA ⚠️ Features LOCK {ADD,ADC,AND,BTC,BTR,BTS,CMPXCHG,CMPXCH8B,CMPXCHG16B

DNSTake — A fast tool to check missing hosted DNS zones that can lead to subdomain takeover
DNSTake — A fast tool to check missing hosted DNS zones that can lead to subdomain takeover

DNSTake — A fast tool to check missing hosted DNS zones that can lead to subdomain takeover

Analyse binaries for missing security features, information disclosure and more.
Analyse binaries for missing security features, information disclosure and more.

extrude Analyse binaries for missing security features, information disclosure and more. 🚧 Extrude is in the early stages of development, and current

Spriting that sass has been missing

Wellington Wellington adds spriting to the lightning fast libsass. No need to learn a new tool, this all happens right in your Sass! OS Support Binari

Domo is a Discord bot to help you manage your FOMO (fear of missing out).

domo domo is a Discord bot to help you manage your FOMO (fear of missing out). Development Download and install Go: Instructions To run the bot first

The missing git branch --interactive

git branch-i I got cross that there's no git branch --interactive, so I made this. It's a very (very) simple curses-mode git branch/git checkout alter

Go program that fetches urls and prepends http:// if missing

fetchautoprefix This is an exercise of the book The Go Programming Language, by

A command line tool for filling missing metric values on Mackerel.

mackerel-null-bridge A command line tool for filling missing metric values on Mackerel. Description When sending error metrics, etc., you may be force

Generic types that are missing from Go, including sets, trees, sorted lists, etc.

go-typ Generic types that are missing from Go, including sets, trees, sorted lists, etc. All code is implemented with 0 dependencies and in pure Go co

A Go (golang) package that enhances the standard database/sql package by providing powerful data retrieval methods as well as DB-agnostic query building capabilities.

ozzo-dbx Summary Description Requirements Installation Supported Databases Getting Started Connecting to Database Executing Queries Binding Parameters

Go Package Manager (gopm) is a package manager and build tool for Go.

🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 In favor of Go Modules Proxy since Go 1.11, this pr

Package set is a small wrapper around the official reflect package that facilitates loose type conversion and assignment into native Go types.

Package set is a small wrapper around the official reflect package that facilitates loose type conversion and assignment into native Go types. Read th

Go package providing simple database and server interfaces for the CSV files produced by the sfomuseum/go-libraryofcongress package
Go package providing simple database and server interfaces for the CSV files produced by the sfomuseum/go-libraryofcongress package

go-libraryofcongress-database Go package providing simple database and server interfaces for the CSV files produced by the sfomuseum/go-libraryofcongr

A package for running subprocesses in Go, similar to Python's subprocesses package.

A package for running subprocesses in Go, similar to Python's subprocesses package.

Utility to restrict which package is allowed to import another package.

go-import-rules Utility to restrict which package is allowed to import another package. This tool will read import-rules.yaml or import-rules.yml in t

A package for running subprocesses in Go, similar to Python's subprocesses package.

Subprocesses Spawn subprocesses in Go. Sanitized mode package main import ( "log" "github.com/estebangarcia21/subprocess" ) func main() { s := s

Comments
  • Respect json omitempty tag

    Respect json omitempty tag

    Currently adding omitempty in json tag has no impact.

    Expected behavior is that fields having valid = false should not be marshalled if omitempty is set.

    opened by ribice 1
  • Reduce dependency on time.Time

    Reduce dependency on time.Time

    Currently most of the date/time calculations are done by converting to time.Time and reverting afterwards to dt format.

    Ideally this step should be removed and the logic should be re-implemented from time.Time into dt.

    opened by ribice 0
Releases(v0.2)
Owner
Emir Ribić
Emir Ribić
A Go package for working with dates

date Package date provides functionality for working with dates. This package introduces a light-weight Date type that is storage-efficient and conven

Rick Beton 100 Dec 13, 2022
Go package for calculating the sunrise and sunset times for a given location

go-sunrise Go package for calculating the sunrise and sunset times for a given location based on this method. Usage To calculate sunrise and sunset ti

Nathan Osman 64 Dec 13, 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
A Go package for working with dates

date Package date provides functionality for working with dates. This package introduces a light-weight Date type that is storage-efficient and coveni

FXT Labs 14 May 24, 2022
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

Bardo Go Framework 1 Mar 21, 2022
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.

MergeStat 289 Dec 25, 2022
Gos: Armed Golang 💪 ( solutions for go module, goproxy, cross compilation, etc.)

The current gos is still an alpha version, welcome more heroes to comment and improve it ?? , you can add more commands to it, or modify something to make it perform better.

storyicon 373 Sep 15, 2022
A simple, semantic and developer-friendly golang package for datetime

Carbon 中文 | English carbon 是一个轻量级、语义化、对开发者友好的 Golang 时间处理库,支持链式调用和 gorm、xorm、zorm 等主流 orm。 如果您觉得不错,请给个 star 吧 github:github.com/golang-module/carbon g

null 2.8k Jan 9, 2023
The standard library flag package with its missing features

cmd Package cmd is a minimalistic library that enables easy sub commands with the standard flag library. This library extends the standard library fla

Eyal Posener 35 Oct 4, 2022