Gostradamus: Better dateTimes in Go

Because dates are difficult in every language

Image by tigerlily713 on Pixaby

Working with the time package in Go is hard. And I think that a lot of Go programmers see it the same way.

Parsing time, replacing days of a time.Time object, and other operations are not natural compared to other languages.

For example, parsing a string into a time.Time object looks like this:

import "time" parsed, err := time.Parse(

"02.01.2006 15:04:05",

"09.04.2020 11:49:54",

)

And replacing the day of the current time object looks like this:

The time package provides all needed functionality, but still, it takes too much knowledge of the package itself to get to a slim solution.

So I programmed Gostradamus: Better DateTimes in Go to simplify dateTime handling and parsing/formatting.

Let’s take the examples above and implement them in Gostradamus:

import "github.com/bykof/gostradamus" parsed, err := gostradamus.Parse(

"09.04.2020 11:49:54",

"DD.MM.YYYY HH:mm:ss",

)

Pretty easy huh? And also a really common way to parse dates and times. Here’s where you can find all the parsing tokens.

The second example would look like this in Gostradamus:

Working with dateTime s was never so easy in Go. You can look up some of the features in the Github Readme or all the features in the go.dev reference. It’s also fully compatible with time.Time and can be parsed from and to it.

I hope I can help you a lot with my new package. If you want to improve or add functionality, feel free to contribute.