foam3

DateTimeUTC Property Type in FOAM3

Overview

DateTimeUTC is a FOAM3 property type that handles date-time values with consistent UTC timezone treatment. It ensures all datetime values are stored, parsed, and displayed in UTC, eliminating timezone ambiguity across users and servers.

Location: foam3/src/foam/lang/types.js Extends: foam.lang.DateTime Java Type: java.util.Date (inherited from the DateTimeJavaRefinement of foam.lang.DateTime in foam3/src/foam/java/refinements.js) Related Utilities:


What It Does

DateTimeUTC provides three core guarantees:

  1. UTC Storage - All values stored as UTC timestamps internally
  2. UTC Parsing - String inputs always interpreted as UTC (not local timezone) using DateUtil.parseDateTimeUTC()
  3. UTC Display - Values always formatted in UTC timezone using DateUtil.formatWithTimeControl(date, timeFirst, 'UTC')

This eliminates timezone-related bugs where the same datetime appears differently to users in different timezones.


Property Type Comparison

Property Type String Parsing Time Component Normalization Use Case
Date Local timezone Ignored (sets to noon) Noon UTC Birth dates, deadlines
DateTime DateParser, local timezone Preserved as-is None (local) User-local events
DateTimeUTC Forced UTC Preserved in UTC All UTC Logs, transactions, API timestamps

What “sets to noon” means for a Date. The adapt rebuilds every value as noon UTC of the value’s local calendar day: new Date(Date.UTC(d.getFullYear(), d.getMonth(), d.getDate(), 12)) (src/foam/lang/types.js:242-250). Two values on the same local day become exactly equal, and consecutive days are exactly 24 hours apart, so plain equality is a same-day test. The time of day is discarded, and a test fixture built as a stored date + 24h - 1ms does not stay on the same day: it lands on the next day’s noon. Build same-day fixtures from the same timestamp and next-day fixtures with exactly + 24h. Use DateTime or DateTimeUTC when the instant matters.


Input Handling

DateTimeUTC uses foam.util.DateUtil.parseDateTimeUTC() which delegates to foam.parse.DateParser.parseDateTimeUTC():

1. Number (Timestamp)

2. Date Object

3. String with Time Component

4. String with Date Only

5. String with Timezone Information


Output Formatting

DateTimeUTC always formats in UTC timezone via foam.util.DateUtil.formatWithTimeControl(date, timeFirst, 'UTC'). The property’s format(val, timeFirst = false) defaults timeFirst to false, so it includes the time unless null is passed. The examples below are the English form; in the browser the date and time follow the client locale:

Format uses:


Current Limitations

1. Date-Only Inputs Set to Midnight UTC (Not Noon)

2. Timezone Information Not Preserved After Conversion

3. Timezone Abbreviations Not Supported


See Also