GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - hmoragrega/after: A Go lang micro library to parse english time descriptions to Go native time durations

BranchesTags
Open more actions menu

Latest commit

 

History

21 Commits
21 Commits

Folders and files

NameName
Last commit message
Last commit date
.travis.yml
.travis.yml
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
parser.go
parser.go
 
 
parser_test.go
parser_test.go
 
 

Repository files navigation

After godoc Build Status Go Report Card

A Go lang micro library to parse english future or past time events to Go native time objects

Examples

  • 10s: after ten seconds
  • +1 minute: after one minute
  • 2 hours: after two hours
  • -1 day: minus one day
  • -2w: minus two weeks

Installation

go get github.com/hmoragrega/after

Usage

parser := after.New()

// "Duration" returns a time.Duration object with the equivalent of the input
anHour, err := parser.Duration("1 hour")

// SinceNow returns a time.Time object that represents the current point in time plus (or minus) the specified duration
inTenMinutes, err := parser.SinceNow("10 minutes")

// "Since" returns a time.Time object that represents the given point in time plus the specified input
nowAgain, err := parser.Since(inTenMinutes, "-10 minutes")

Available units

The available time units are

  • ms, millisecond or milliseconds
  • s, second or seconds
  • m, minute or minutes
  • h, hour or hours
  • d, day or days
  • w, week or weeks

Multiplier

It's the number that will multiply the time unit:

  • It must start with 1 to 9
  • It can be signed, both positive or negative.
  • Omitting the sign is equivalent to using a plus sign

Validation

You can use this regular expression to validate your inputs:

^((\+|\-))?([1-9][0-9]*)\s?(ms|milliseconds?|s|seconds?|m|minutes?|h|hours?|d|days?|w|weeks?)$

Scope

The scope of the library is small on purpose, if you are looking for a more full-fledged solution check out olebedev's when

About

A Go lang micro library to parse english time descriptions to Go native time durations

Resources

Readme
Apache-2.0 license
Activity

Stars

7 stars

Watchers

2 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.