Disambiguating Local Wall-Clock Parsing
When parsing a local wall-clock timestamp during a DST fall-back overlap (where the same local time occurs twice), GLib generally favors the earlier UTC instant (the DST offset). This behavior is not explicitly documented as a stable API guarantee because GLib wraps the underlying system C library's mktime() implementation, which varies between glibc and musl.
Verifying the Selected Offset
Since the GLib.DateTime API does not provide a "fold" parameter to choose the offset during instantiation, you must verify the selection after the object is created. Use the get_offset() method to determine the UTC offset in seconds.
// Example: Verifying the offset after parsing
var dt = DateTime.new_local_date_time(year, month, day, hour, min, sec);
int offset = dt.get_offset();
stdout.printf("Selected UTC offset: %d seconds\n", offset);
Safe Regional Conversion Patterns
To ensure consistent behavior across different environments (especially in minimal containers), follow these patterns:
- Explicit TimeZone Objects: Avoid relying on the system's default local time. Use
GLib.TimeZone.new("Region/City") to ensure the application uses a specific zoneinfo database entry.
- TZData Validation: Ensure the
tzdata package is installed in your deployment image. Without /usr/share/zoneinfo, GLib may default to UTC, making local parsing identical to UTC parsing and masking DST overlap issues.
- UTC-First Storage: Always convert local wall-clock time to UTC immediately upon ingest and store the resulting Unix timestamp.
Verification Steps
To confirm how your specific environment handles the overlap, run a test case using a known fall-back date (e.g., the last Sunday of October for EU zones):
- Instantiate a
DateTime object for a time that exists in both offsets.
- Print the result of
get_offset().
- Compare this value against the output of the system
date command on the same host to ensure GLib is aligned with the OS.
Diagnostic Note: Are you deploying this application in a scratch-based container or a standard distribution image? If the tzdata package is missing, the offset will always return 0 regardless of the requested timezone.