A Go package for converting `year-month-day` expressions to and from 8-byte integers following the model of the CIDOC‐CRM Temporal representation specification.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
LICENSE
Makefile
README.md
temporal.go

README.md

go-whosonfirst-temporal

A Go package for converting year-month-day expressions to and from 8-byte integers modeled after the model of the CIDOC‐CRM Temporal representation specification.

Caveats

This package is under active development. It is incomplete and probably still has bugs. Among other things:

  • This does not implement the CIDOC‐CRM Temporal specification – specifically the numeric representations of dates are not the same
  • It does not handle period "expressions" or any of signifiers yet
  • It does not handle years greater than 9999 (or less than -9999) yet because Go's date parser appears to be built on top of MADNESS...
  • It does not implement temporal operators yet

It does not implement complete CIDOC-CRM (textual) temporal expressions nor will it. Currently there are a handful of NewThingFromString functions which allow for simple YYYY-MM-DD BCE? strings but these will probably be replaced or at least superseded by equivalent functions that hide more complex string parsing from this package. We'll see.

Example

import (
       "fmt"
       "github.com/whosonfirst/go-whosonfirst-temporal"
       )

func main (){

     lower := "1914-08-04"
     upper := "1918-11-11"

     s := fmt.Sprintf("%s,%s", lower, upper)
     w, _ := temporal.NewTimeWedgeFromString(s)

     fmt.Printf("wedge: %v\n", w)
     fmt.Printf("lower: %v\n", w.Lower())
     fmt.Printf("upper: %v\n", w.Upper())

     lower_int := w.Lower().AsInt()
     upper_int := w.Upper().AsInt()

     fmt.Printf("lower (as int): %d\n", lower_int)
     fmt.Printf("upper (as int): %d\n", upper_int)

     lower_slice, _ := temporal.NewTimeSliceFromInt(lower_int)
     upper_slice, _ := temporal.NewTimeSliceFromInt(upper_int)

     fmt.Printf("lower (from int): %v (%d)\n", lower_slice, lower_slice.AsInt())
     fmt.Printf("upper (from int): %v (%d)\n", upper_slice, upper_slice.AsInt())
}

The output of this program would be:

wedge: 1914-08-04,1918-11-11
lower: 1914-08-04
upper: 1918-11-11
lower (as int): 125469184
upper (as int): 125744576
lower (from int): 1914-08-04 (125469184)
upper (from int): 1918-11-11 (125744576)

If you changed the upper and lower dates to be 00-01-01 and 00-01-01 BCE respectively the output would be:

wedge: 0000-01-01 BCE,0000-01-01
lower: 0000-01-01 BCE
upper: 0000-01-01
lower (as int): -4224
upper (as int): 4288
lower (from int): 0000-01-01 BCE (-4224)
upper (from int): 0000-01-01 (4288)

Not discussed here is the TimePie which is a named pair of TimeWedge object-thingies.

See also