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.
Dagger exposes the git committer date as a
String!("Git committer date, inRFC3339 format"). I want to use it as
SOURCE_DATE_EPOCHfor reproduciblebuilds, which means parsing that string and turning it into a Unix timestamp.
Today there is no way to do that from Dang.
Example:
Proposed API
Construction
time.RFC3339; fractional seconds allowed).This is exactly what git's
%cIand Dagger's field produce.Path/Regexp:DateTime: invalid RFC 3339 timestamp "yesterday"(works withrescue).time.RFC3339Nano,offset preserved. For git dates this is a no-op (
+00:00→Zis theonly visible normalization). Same normalize-on-construction idea as
Path.JSON/YAML/TOML.decodeinto aDateTime!-typed field goes throughthe same hook automatically (existing codec scalar path).
Statics (
DateTime.x)DateTime.now: DateTime!DateTime.fromUnix(seconds: Int!): DateTime!secondsafter the Unix epoch, in UTCMethods (
d.x)unix: Int!isBefore(other: DateTime!): Boolean!isAfter(other: DateTime!): Boolean!string: String!Path.string)Exit is free under the existing scalar rules: a
DateTime!degrades toString!at any value-handoff boundary, andtoString/ interpolation yieldthe RFC 3339 text, so it can be passed straight back into any Dagger
String!argument.