A fast ISO8601 date parser for Go

Overview

A fast ISO8601 date parser for Go

go.dev reference GoDoc Build Status Go Report Card

go get github.com/relvacode/iso8601

The built-in RFC3333 time layout in Go is too restrictive to support any ISO8601 date-time.

This library parses any ISO8601 date into a native Go time object without regular expressions.

Usage

import "github.com/relvacode/iso8601"

// iso8601.Time can be used as a drop-in replacement for time.Time with JSON responses
type ExternalAPIResponse struct {
	Timestamp *iso8601.Time
}


func main() {
	// iso8601.ParseString can also be called directly
	t, err := iso8601.ParseString("2020-01-02T16:20:00")
}

Benchmark

BenchmarkParse-16        	13364954	        77.7 ns/op	       0 B/op	       0 allocs/op
You might also like...
Installs git repos onto your system and keeps them up-to-date

Gitfile Installs git repos onto your system and keeps them up-to-date. It's a lightweight package manager for things that haven't been published to a

A simple Cron library for go that can execute closures or functions at varying intervals, from once a second to once a year on a specific date and time. Primarily for web applications and long running daemons.

Cron.go This is a simple library to handle scheduled tasks. Tasks can be run in a minimum delay of once a second--for which Cron isn't actually design

manage your mocks / run mockgen more quickly / mocks up-to-date checking
manage your mocks / run mockgen more quickly / mocks up-to-date checking

gomockhandler If you find any bugs or have feature requests, please feel free to create an issue. gomockhandler is handler of golang/mock, as the name

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

Watchtower for Git: automatically keep local Git repositories up to date with their remotes

CrowsNest Watchtower for Git: automatically keep local Git repositories up to date with their remotes. Configuration Flags --run-once or -r: Normally

Birthdays is a web service that stores the birthday date of users and calculates the remaining days until the user's birthday.
Birthdays is a web service that stores the birthday date of users and calculates the remaining days until the user's birthday.

Birthdays is a web service that stores the birthday date of users and calculates the remaining days until the user's birthday. Features Metrics servic

indodate is a plugin for golang programming language for date convertion on indonesian format

indodate is a package for golang programming language for date conversion on indonesian format

Command-line tool to organize large directories of media files recursively by date, detecting duplicates.

go-media-organizer Command-line tool written in Go to organise all media files in a directory recursively by date, detecting duplicates.

Advent of Code Input Loader, provide a session cookie and a problem date, returns a string or []byte of the input

Advent of Code Get (aocget) A small lib to download your puzzle input for a given day. Uses your session token to authenticate to obtain your personal

Installs git repos onto your system and keeps them up-to-date

Gitfile Installs git repos onto your system and keeps them up-to-date. It's a lightweight package manager for things that haven't been published to a

A pay later service to allow our users to buy goods from a merchant now, and then allow them to pay for those goods at a later date.

simple-pay-later A pay later service to allow our users to buy goods from a merchant now, and then allow them to pay for those goods at a later date.

This package can parse date match expression, which used by ElasticSearch

datemath-parser this package is pure go package, this package can parse date match expression, which used by ElasticSearch. Date Math Definition you c

This package can parse date match expression, which used by ElasticSearch

datemath-parser this package is pure go package, this package can parse date match expression, which used by ElasticSearch. Date Math Definition you c

A binary that continuously displays Ethiopian date and time (Amharic). best used in i3-status.

i3-eth-time Display ethiopian calendar date/time in i3-wm! Intended for use in i3-status. How to use Clone/Download repo and compile Open up your i3co

To copy a secret to another namespace and sync it up-to-date

Secret Mirror Operator This kubebuilder-based Kubernetes operator copies a Secret to another namespace and synchronizes it with the custom resource Se

Shows the calender for current month according to the date input by the user.

#Calender This program shows the Calender of a month according to the date input by the user. ##Sample Run Enter a date: 12/1/2022 Please find the req

CLI tool for endoflife.date

eol eol is command line tool for endoflife.date. This is mostly inspired from norwegianblue built in python. getting Started go install github.com/kob

Blockcain - Trust Wallet token repository - A comprehensive, up-to-date collection of information about several thousands (!) of crypto tokens
Fast JSON parser and validator for Go. No custom structs, no code generation, no reflection

fastjson - fast JSON parser and validator for Go Features Fast. As usual, up to 15x faster than the standard encoding/json. See benchmarks. Parses arb

Comments
  • ParseString does not fail on invalid input string

    ParseString does not fail on invalid input string

    As per the documentation, ParseString parses an ISO8601 compliant date-time string into a time.Time object

    However, if you try to parse an invalid string, e.g. 2020-02-30T10:24:54, ParseString does not raise any error whereas the date is not valid.

    You can test here: https://play.golang.org/p/4fqmGeTsrjF

    opened by Gaadek 4
  • FIX issue with the time set to zero

    FIX issue with the time set to zero

    After paring a date with this value "0000-00-00" internally the date is looking like -0001-12-31 00:00:00 +0000 UTC so for the round trip json Unmarshal/Marshal you can get this current error : json: error calling MarshalJSON for type iso8601.Time: Time.MarshalJSON: year outside of range [0,9999]

    To keep is safe I use the default zeroed time of Go witch is 0001-01-01 00:00:00 +0000 UTC

    opened by ritoon 2
  • Timezone of

    Timezone of "-00" and "-00:00" should be invalid per ISO8601 3.4.2

    Wikipedia's breakdown of ISO8601 Section 3.4.2:

    An offset of zero, in addition to having the special representation "Z", can also be stated numerically as "+00:00", "+0000", or "+00". However, it is not permitted to state it numerically with a negative sign, as "−00:00", "−0000", or "−00". The section dictating sign usage (section 3.4.2 in the 2004 edition of the standard) states that a plus sign must be used for a positive or zero value, and a minus sign for a negative value. Contrary to this rule, RFC 3339, which is otherwise a profile of ISO 8601, permits the use of "-00", with the same denotation as "+00" but a differing connotation.

    package main
    
    import (
    	"github.com/relvacode/iso8601"
    	"github.com/davecgh/go-spew/spew"
    )
    
    func main() {
    	t, err := iso8601.ParseString("2020-01-02T16:20:00.999-00")
    	spew.Dump(t, err)
    }
    

    Outputs

    (time.Time) 2020-01-02 16:20:00.999 +0000 +0000
    (interface {}) <nil>
    

    when it should be outputting an error.

    opened by gavbaa 0
  • Various v2 additions

    Various v2 additions

    1. Fixes error in go.mod - this is necessary for anyone to use v2.x
    2. Adds Of function for convenient (i.e less syntax) conversion from time.Time to iso8601.Time.
    3. Adds Equal and String methods to override the base time.Time behaviour (which is inappropriate)
    4. Adds more test cases
    5. Adds some comments to explain some reasoning

    This is a bit of a smorgasbord with 5 minor things in one PR. I hope you think it's a worthwhile step forward though. We can discuss merging the different parts separately if you feel it's necessary.

    opened by rickb777 6
Releases(v2.0.0)
Owner
Jason Kingsbury
Small solutions for big systems
Jason Kingsbury
GoLang Parse many date strings without knowing format in advance.

Go Date Parser Parse many date strings without knowing format in advance. Uses a scanner to read bytes and use a state machine to find format. Much fa

Aaron Raddon 1.8k Nov 27, 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
Go-timeparser - Flexible Time Parser for Golang

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

Kazuaki Yamamoto 1 Jun 9, 2022
fasttime - fast time formatting for go

fasttime - fast time formatting for go

phuslu 68 Nov 1, 2022
Fast strftime for Go

strftime Fast strftime for Go SYNOPSIS f := strftime.New(`.... pattern ...`) if err := f.Format(buf, time.Now()); err != nil { log.Println(err.Err

null 93 Nov 28, 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 5, 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 Nov 11, 2022
GoLang Parse many date strings without knowing format in advance.

Go Date Parser Parse many date strings without knowing format in advance. Uses a scanner to read bytes and use a state machine to find format. Much fa

Aaron Raddon 1.8k Nov 27, 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
A simple Cron library for go that can execute closures or functions at varying intervals, from once a second to once a year on a specific date and time. Primarily for web applications and long running daemons.

Cron.go This is a simple library to handle scheduled tasks. Tasks can be run in a minimum delay of once a second--for which Cron isn't actually design

Robert K 215 Nov 19, 2022