https://github.com/dontlaugh/lilrange
DSL for UTC time ranges, e.g. parse "0400-0800" as a Duration
https://github.com/dontlaugh/lilrange
dsl duration-parsing time-range utc
Last synced: 11 months ago
JSON representation
DSL for UTC time ranges, e.g. parse "0400-0800" as a Duration
- Host: GitHub
- URL: https://github.com/dontlaugh/lilrange
- Owner: dontlaugh
- Created: 2019-07-14T17:21:10.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-07-15T12:43:34.000Z (almost 7 years ago)
- Last Synced: 2025-02-16T13:04:24.967Z (over 1 year ago)
- Topics: dsl, duration-parsing, time-range, utc
- Language: Go
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# lilrange
An opinionated string DSL for creating UTC time ranges.
## Usage
Get a `lilrange.Range` from a string.
```go
range, err := lilrange.Parse("0000-0400")
```
The returned range's `End` time is guaranteed to be in the future. The `Start`
time could be in the past, or the future.
To determine if your current system time is inside the range, pass a `time.Time`
to the `Within` method.
```go
// get a lilrange.Range
r, _ := lilrange.Parse("0130-0230")
// get the current time with Go's time package
now := time.Now()
// Are we within the Range?
if r.Within(now) {
fmt.Println("We are inside the range")
}
```
## Test Program
A test program can be compiled from the *lilrange* sub directory, or use `go get -u`
if `$GOPATH/bin` is on your PATH.
```
go get -u github.com/dontlaugh/lilrange/lilrange
```
Give it a lilrange string to test the behavior.
```
lilrange 0415-0445
```