Guard Time

ISO 8601 / RFC 3339 datetime identifier-safety guard. Validates user-supplied datetime strings destined for audit timestamps, scheduling, retention windows, query ranges, and cross-system event correlation. KIND="identifier" — the gate consumes ctx.identifier / ctx.timestamp / ctx.time.

Threat catalog: shape malformation (not RFC 3339 datetime grammar); pre-epoch / far-future (year before 1970 or after the operator's ceiling, default 9999 — often a parsing bug or sentinel-leak shape); naive datetime with no offset (strict refuses — downstream interpretation depends on local timezone, breaks cross-region equality); non-UTC offset (strict accepts only Z / +00:00; balanced accepts any offset; permissive allows naive too); leap-second 60 in seconds field (RFC 3339 §5.6 explicitly valid, most parsers panic — flagged-by-default with operator policy); excessive fractional precision (cap at 9 digits = nanosecond floor); date-only / time-only refused for full-datetime contexts; BIDI / zero-width / C0-control / null-byte universal-refuse.

Far-future / pre-epoch refusal is critical-severity by default: year-2038 wrap shapes, Y10K sentinels, and 0000-01-01 poison pills routinely leak through downstream parsers as silent NaN / 0 rows; the guard refuses at the boundary instead.

Profiles: strict / balanced / permissive. Compliance postures: hipaa / pci-dss / gdpr / soc2.

b.guardTime.validate(input, opts?) #

stable0.7.46hipaapci-dssgdprsoc2
{
  profile:                "strict"|"balanced"|"permissive",
  compliancePosture: "hipaa"|"pci-dss"|"gdpr"|"soc2",
  bidiPolicy:             "reject"|"strip"|"audit"|"allow",
  controlPolicy:          "reject"|"strip"|"allow",
  nullBytePolicy:         "reject"|"strip"|"allow",
  zeroWidthPolicy:        "reject"|"strip"|"allow",
  naiveDatetimePolicy:    "reject"|"audit"|"allow",
  nonUtcOffsetPolicy:     "reject"|"audit"|"allow",
  leapSecondPolicy:       "reject"|"audit"|"allow",
  fractionalDigitsPolicy: "reject"|"truncate"|"audit"|"allow",
  dateOnlyPolicy:         "reject"|"audit"|"allow",
  timeOnlyPolicy:         "reject"|"audit"|"allow",
  minYear:                number,    // default 1970
  maxYear:                number,    // default 9999
  maxFractionalDigits:    number,    // default 9 (nanosecond)
  maxBytes:               number,    // default 64
}

Inspect a datetime string against the resolved profile and return { ok, issues }. Each issue carries kind / severity (critical | high | medium | low) / ruleId / snippet. Non-string input returns a single time.bad-input issue rather than throwing — callers that prefer an exception use b.guardTime.sanitize.

var rv = b.guardTime.validate("2026-05-05T12:34:56Z", { profile: "strict" });
rv.ok;                                             // → true

var bad = b.guardTime.validate("1969-12-31T23:59:59Z", { profile: "strict" });
bad.ok;                                            // → false
bad.issues[0].ruleId;                              // → "time.year-window"

b.guardTime.sanitize(input, opts?) #

stable0.7.46
{
  profile:                "strict"|"balanced"|"permissive",
  compliancePosture: "hipaa"|"pci-dss"|"gdpr"|"soc2",
  ...:                    same shape as b.guardTime.validate opts,
}

Normalize a datetime string in-place: replace the legacy space-separator with T, upper-case the trailing Z UTC marker. Throws GuardTimeError when any critical or high issue fires (year out of range, leap-second under reject, naive datetime under reject). Use validate to inspect issues without throwing.

var safe = b.guardTime.sanitize("2026-05-05 12:34:56z",
                                { profile: "balanced" });
safe;                                              // → "2026-05-05T12:34:56Z"

try {
  b.guardTime.sanitize("9999-12-31T23:59:60Z", { profile: "strict" });
} catch (e) {
  e.code;                                          // → "time.leap-second"
}

b.guardTime.compliancePosture(name) #

stable0.7.46hipaapci-dssgdprsoc2

Look up a compliance-posture overlay by name (one of "hipaa" / "pci-dss" / "gdpr" / "soc2"). Returns a fresh clone of the posture overlay so the caller may mutate it freely without disturbing the shared table. Throws GuardTimeError with code "time.bad-posture" when the name is not one this guard maps. Wired by gateContract.defineGuard through gateContract.lookupCompliancePosture, so the clone semantics and error code are identical across every guard in the family.

var posture = b.guardTime.compliancePosture("hipaa");
posture;                                             // → overlay clone (mutable)

try {
  b.guardTime.compliancePosture("not-a-regime");
} catch (e) {
  e.code;                                            // → "time.bad-posture"
}

b.guardTime.buildProfile(opts) #

stable0.7.46
{
  extends:   string|string[],   // base profile name(s) to compose
  ...:       any guard key,      // inline override of resolved keys
}

Compose a derived profile from one or more named bases plus inline overrides, resolving names through this guard's own PROFILES table. opts.extends is a base profile name ("strict" / "balanced" / "permissive") or an array of names — later entries shadow earlier ones, and inline opts keys win last. Wired by gateContract.defineGuard through gateContract.makeProfileBuilder, so operator-defined profiles stay traceable to a baseline instead of a hand-typed dictionary.

var custom = b.guardTime.buildProfile({ extends: "strict" });
custom;                                              // → composed profile object

b.guardTime.loadRulePack(pack) #

stable0.7.46

Register an operator-supplied rule pack with this guard's rule-pack registry. The pack is identified by pack.id (a non-empty string) and stored for later dispatch by gates that opt in via opts.rulePackId. Returns the pack unchanged on success; throws GuardTimeError with code "time.bad-opt" when pack is missing or pack.id is not a non-empty string. Wired by gateContract.defineGuard through gateContract.makeRulePackLoader, so storage shape and validation are identical across the family.

var pack = b.guardTime.loadRulePack({ id: "tenant-policy", rules: [] });
pack.id;                                             // → "tenant-policy"

b.guardTime.gate(opts?) #

stable0.7.46
{
  profile:           string,    // one of PROFILES; default this guard's default
  compliancePosture: string,    // overlay one of hipaa/pci-dss/gdpr/soc2
  mode:              string,    // one of gateContract MODES; default "enforce"
}

Build the guard's request-boundary gate — a contract-shaped object exposing check(ctx) that host primitives call at their byte moment. This is the factory default chain: serve when no issue, audit-only for info / warn issues, and refuse for any high / critical issue, dispatched to the right ctx field by the guard's KIND. Wired by gateContract.defineGuard through gateContract.buildGuardGate; a guard whose gate diverges (a bespoke sanitize-and-reserialize chain, for example) ships its own gate block instead of this template.

var gate = b.guardTime.gate({ profile: "strict" });
var decision = await gate.check({ bytes: Buffer.from("...") });
decision.action;                                     // → "serve" | "refuse" | …

b.guardTime.resolveOpts(opts?) #

stable0.7.46
{
  profile:           string,    // one of PROFILES; default this guard's default
  compliancePosture: string,    // overlay one of hipaa/pci-dss/gdpr/soc2
}

Resolve caller opts against this guard's PROFILES + compliance-posture overlays into the fully-defaulted option set the guard runs on — the same resolution validate / sanitize / gate apply internally. Wired by gateContract.defineGuard from the guard's binding config (profiles / postures / defaults / error class), so a guard's bespoke gate calls resolveOpts instead of re-declaring the per-guard resolver wrapper. Throws GuardTimeError with code "time.bad-opt" / "time.bad-posture" on an unknown profile or posture name.

var resolved = b.guardTime.resolveOpts({ profile: "strict" });
resolved.profile;                                    // → "strict"

Last updated 2026-08-08T16:39:49.652Z by seeder.