https://github.com/carmo-evan/strtotime
A golang implementation of strtotime
https://github.com/carmo-evan/strtotime
golang golang-library golang-wrapper php strtotime
Last synced: 3 months ago
JSON representation
A golang implementation of strtotime
- Host: GitHub
- URL: https://github.com/carmo-evan/strtotime
- Owner: carmo-evan
- License: other
- Created: 2019-09-30T02:04:10.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-01-08T20:31:56.000Z (over 6 years ago)
- Last Synced: 2024-06-18T20:15:06.780Z (almost 2 years ago)
- Topics: golang, golang-library, golang-wrapper, php, strtotime
- Language: Go
- Size: 53.7 KB
- Stars: 57
- Watchers: 1
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.repostatus.org/#active)
# strtotime

Golang implementation of `strtotime`, a very popular PHP function for converting English text to a timestamp. This is an exercise inspired on [this](https://github.com/kvz/locutus/blob/master/src/php/datetime/strtotime.js) Javascript implementation.
## Installation
`strtotime` uses Go modules and is compatible with Go 1.12 upwards. Install using `go get`.
```
go get github.com/carmo-evan/strtotime
```
After importing it, the `strtotime` package will expose only one method: `Parse`. It takes two arguments - an English string describing some point in time; and a unix timestamp that should represent the current time, or another referencial point in time you want to use.
Try it on [the playground](https://play.golang.org/p/k3RqaQy7CB-).
```go
package main
import (
"fmt"
"github.com/carmo-evan/strtotime"
"time"
)
func main() {
//Now is Nov 17, 2019
u, err := strtotime.Parse("next Friday 3pm", time.Now().Unix())
if err != nil {
// crash and burn
}
t := time.Unix(u,0)
fmt.Println(t)
//output: 2019-11-22 15:00:00 +0000 UTC
}
```
## Supported Formats
- [x] yesterday
- [x] now
- [x] noon
- [x] midnightOrToday
- [x] tomorrow
- [x] timestamp
- [x] firstOrLastDay
- [x] backOrFrontOf (Thank you [evalevanto!](https://github.com/evalevanto))
- [ ] weekdayOf
- [x] mssqltime
- [x] timeLong12
- [x] timeShort12
- [x] timeTiny12
- [x] soap
- [x] wddx
- [x] exif
- [x] xmlRpc
- [x] xmlRpcNoColon
- [x] clf
- [x] iso8601long
- [x] dateTextual
- [x] pointedDate4
- [x] pointedDate2
- [x] timeLong24
- [x] dateNoColon
- [x] pgydotd
- [x] timeShort24
- [x] iso8601noColon
- [x] dateSlash
- [x] american
- [x] americanShort
- [x] gnuDateShortOrIso8601date2
- [x] iso8601date4
- [x] gnuNoColon
- [x] gnuDateShorter
- [x] pgTextReverse
- [x] dateFull
- [x] dateNoDay
- [x] dateNoDayRev
- [x] pgTextShort
- [x] dateNoYear
- [x] dateNoYearRev
- [x] isoWeekDay
- [x] relativeText
- [x] relative
- [x] dayText
- [x] relativeTextWeek
- [x] monthFullOrMonthAbbr
- [x] tzCorrection
- [x] ago
- [x] gnuNoColon2
- [x] year4
- [x] whitespace
### Author
By [Evan do Carmo](https://github.com/carmo-evan)