Skip to content
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

chronic — go-ruby-chronic

Go Reference License: BSD-3-Clause CI Coverage

A pure-Go (no cgo) reimplementation of Ruby's chronic gem — a natural-language date and time parser. It turns English phrases such as "tomorrow", "next tuesday", "3 days ago", "may 27th" or "2016-05-27" into a concrete instant (or a Span), faithfully mirroring the deterministic grammar of chronic 0.10.2without any Ruby runtime.

It is the natural-language time backend for go-embedded-ruby, but is a standalone, reusable module with no dependency on the Ruby runtime — a sibling of go-ruby-regexp (the Onigmo engine) and go-ruby-erb (the ERB compiler).

Deterministic by construction

Parse is deterministic: pass a fixed anchor via Options.Now and the result depends only on the input string, so it needs no interpreter and no wall clock. Its output is differential-tested byte-for-byte against MRI's own chronic gem.

Usage

import (
	"time"

	"github.com/go-ruby-chronic/chronic"
)

now := time.Date(2006, 8, 16, 14, 0, 0, 0, time.Local)
t, _ := chronic.Parse("tomorrow", chronic.Options{Now: now})
// t == 2006-08-17 12:00:00

Tests & coverage

go test ./... runs the unit, golden and differential-oracle suites. The CI gate enforces 100% statement coverage and builds/tests on all six 64-bit Go targets — amd64, arm64, riscv64, loong64, ppc64le, s390x.

License

BSD-3-Clause. Copyright (c) the go-ruby-chronic/chronic authors.

WebAssembly

Being pure Go (CGO=0), this library also compiles to WebAssembly — both GOOS=js GOARCH=wasm (browser / Node.js) and GOOS=wasip1 GOARCH=wasm (WASI). CI builds both targets on every push, alongside the six 64-bit native/qemu arches.

GOOS=js     GOARCH=wasm go build ./...   # browser / Node
GOOS=wasip1 GOARCH=wasm go build ./...   # WASI (wasmtime, wasmer, wasmedge, …)

About

Pure-Go (CGO=0) MRI-faithful Ruby chronic

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages