Skip to main content

Deterministic temporal-expression IR engine — Python port of the nl2time natural language ⇄ date/time library

Project description

nl2time (Python)

Deterministic resolution of temporal-expression IR — the Python port of nl2time, a bidirectional natural language ⇄ date/time library built around a JSON intermediate representation (TimeExpr).

Scope of this release: the language-neutral core. IR validation, TimeContext (reference instant, IANA timezone, locale-derived week/date policy, ambiguity knobs), and the full deterministic engine resolve() — every operator including calendar snapping, DST-correct offsets, holidays (computed Easter), business-day spans, and ordered ambiguity candidates. Natural-language parsing and rendering are not yet ported; today the expected producers of IR are the JS parser, an LLM emitting schema-constrained IR, or your own code. Time model: whenever (Temporal-inspired).

from nl2time import TimeContext, resolve

ctx = TimeContext.make({
    "now": "2026-07-20T17:00:00Z",
    "timeZone": "America/Los_Angeles",
    "locale": "en-US",
})

# "last week" as IR (e.g. produced by the JS parser or an LLM):
expr = {
    "op": "snap",
    "base": {"op": "offset", "base": {"op": "now"}, "amount": -1, "unit": "week"},
    "unit": "week",
}
resolve(expr, ctx)["candidates"][0]
# {"kind": "interval", "start": Instant("2026-07-12 07:00:00Z"),
#  "end": Instant("2026-07-19 07:00:00Z"), "grain": "week"}
# (values are `whenever.Instant`; candidates are ordered, ambiguity is data)

Parity guarantee

This engine reproduces the JS reference bit-exactly — instants, grains, and candidate order — across all 2,760 machine-generated engine-parity fixtures derived from the project's six-language conformance corpora, enforced in CI on every commit. Spec: ir-spec.md; strategy: porting.md; test-data provenance: corpus/ATTRIBUTIONS.md.

MIT.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nl2time-0.1.1.tar.gz (29.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nl2time-0.1.1-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

File details

Details for the file nl2time-0.1.1.tar.gz.

File metadata

  • Download URL: nl2time-0.1.1.tar.gz
  • Upload date:
  • Size: 29.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for nl2time-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8d90857ea158fdd83645bedd7210c1ae126de5323a4b489258f87a10588e4022
MD5 b2b0422a16ca4068a3a9d36cc4277627
BLAKE2b-256 6b3901670014bddf35a104b0135a6f71ed434922a95a072e576197c2554cc6ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for nl2time-0.1.1.tar.gz:

Publisher: release.yml on AndyFooBlah/nl2time

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nl2time-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: nl2time-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 19.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for nl2time-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 df037ae586fd40c53ee5de18d60bf3e3a8fb23e62a5abc226d6494ef05698ea1
MD5 9e80ec353df8cdbf9dcdc3254df8a256
BLAKE2b-256 94dc286b6506d519f158e3eba47f0274a3713e8b028237fd1ff202dfe24dd303

See more details on using hashes here.

Provenance

The following attestation bundles were made for nl2time-0.1.1-py3-none-any.whl:

Publisher: release.yml on AndyFooBlah/nl2time

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page