Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ribice/dt
Go's missing DateTime package
https://github.com/ribice/dt
date datetime golang library time
Last synced: 11 days ago
JSON representation
Go's missing DateTime package
- Host: GitHub
- URL: https://github.com/ribice/dt
- Owner: ribice
- License: apache-2.0
- Created: 2019-08-27T10:16:48.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-06-25T21:27:03.000Z (over 4 years ago)
- Last Synced: 2024-10-12T22:34:03.783Z (27 days ago)
- Topics: date, datetime, golang, library, time
- Language: Go
- Size: 34.2 KB
- Stars: 37
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dt
Go's missing DateTime package[![Build Status](https://travis-ci.org/ribice/dt.svg?branch=master)](https://travis-ci.org/ribice/dt)
[![codecov](https://codecov.io/gh/ribice/dt/branch/master/graph/badge.svg)](https://codecov.io/gh/ribice/dt)
[![Go Report Card](https://goreportcard.com/badge/github.com/ribice/dt)](https://goreportcard.com/report/github.com/ribice/dt)## 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:mmUnlike `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](https://github.com/googleapis/google-cloud-go/tree/master/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](LICENSE) file for details.
## Author
[Emir Ribic](https://ribice.ba)