Skip to content

Commit

Permalink
Add tz_offset_secs to date/time test data so ICU4X can use timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
sven-oly committed Sep 13, 2024
1 parent beee83f commit 7a0b787
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions schema/datetime_fmt/test_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
"description": "String in ISO 8601 form, e.g. YYYY-MM-DD hh:mm:ss.sss",
"type": "string"
},
"tz_offset_secs": {
"description": "Offset in timezone from UTC",
"type": "number"
},
"datetime_skeleton": {
"description": "Skeleton for date/time format: https://unicode-org.github.io/icu/userguide/format_parse/datetime/",
"type": "string"
Expand Down
15 changes: 14 additions & 1 deletion testgen/generators/datetime_gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,23 @@ function generateAll(run_limit) {
let zdt = Temporal.ZonedDateTime.from(temporal_date);
let temporal_instant = zdt.toInstant();

let zone_temporal_date = temporal_dates[date_index];
zone_temporal_date['timeZone'] = timezone;
let zdt_zoned = Temporal.ZonedDateTime.from(zone_temporal_date);
const zoned_input_string = zdt_zoned.toString();
const offset_part = zoned_input_string.substring(19,25);
const hours = offset_part.substring(0,3);
const minutes = offset_part.substring(4,6)
const tz_offset_secs =
3600 * Number(hours)+ 60 * Number(minutes);

// Get the ISO string with 'Z'.
let input_string = temporal_instant.toString();

let this_date = new Date(temporal_instant.epochMilliseconds);

const full_input_string = zdt.toString();

let result;
let parts;
try {
Expand Down Expand Up @@ -501,7 +513,8 @@ function generateAll(run_limit) {
const label_string = String(label_num);

let test_case = {
'input_string': input_string
'input_string': input_string,
'tz_offset_secs': tz_offset_secs
};

if (skeleton) {
Expand Down

0 comments on commit 7a0b787

Please sign in to comment.