Skip to content

Feature request: a DateTime scalar #172

Description

@sagikazarmark

Dagger exposes the git committer date as a String! ("Git committer date, in
RFC3339 format"). I want to use it as SOURCE_DATE_EPOCH for reproducible
builds, which means parsing that string and turning it into a Unix timestamp.
Today there is no way to do that from Dang.

Example:

build(src: Directory!, ref: GitRef!): Container! {
  let epoch = DateTime(ref.commitDate).unix
  dag.container.from("alpine")
    .withDirectory("/src", src)
    .withEnvVariable("SOURCE_DATE_EPOCH", toString(epoch))
}

Proposed API

Construction

let d = DateTime(ref.commitDate)           # constructor, for non-literal Strings
let d: DateTime! = "2024-03-01T12:00:00Z"  # literals auto-coerce into a DateTime slot
let d = ref.commitDate :: DateTime!        # explicit cast
  • Accepts RFC 3339 only (Go time.RFC3339; fractional seconds allowed).
    This is exactly what git's %cI and Dagger's field produce.
  • Invalid input raises a recoverable error at the slot, like Path/Regexp:
    DateTime: invalid RFC 3339 timestamp "yesterday" (works with rescue).
  • Canonical form: the parsed value re-rendered with time.RFC3339Nano,
    offset preserved. For git dates this is a no-op (+00:00 → Z is the
    only visible normalization). Same normalize-on-construction idea as Path.
  • JSON / YAML / TOML.decode into a DateTime!-typed field goes through
    the same hook automatically (existing codec scalar path).

Statics (DateTime.x)

Member Doc
DateTime.now: DateTime! the current instant, in UTC (host-TZ independent, so the string form is deterministic across machines)
DateTime.fromUnix(seconds: Int!): DateTime! the instant seconds after the Unix epoch, in UTC

Methods (d.x)

Member Doc
unix: Int! seconds since the Unix epoch
isBefore(other: DateTime!): Boolean! instant comparison
isAfter(other: DateTime!): Boolean! instant comparison
string: String! the canonical RFC 3339 text (mirrors Path.string)

Exit is free under the existing scalar rules: a DateTime! degrades to
String! at any value-handoff boundary, and toString / interpolation yield
the RFC 3339 text, so it can be passed straight back into any Dagger String!
argument.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions