Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timezone revision: separation of rules and offset #35

Merged
merged 12 commits into from
Oct 27, 2024
Merged

Conversation

FObersteiner
Copy link
Owner

@FObersteiner FObersteiner commented Oct 25, 2024

  • revise how time zones and UTC offsets are handled, so that a pointer to a (constant) Timezone can be used to make zoned datetime
  • verify that handling of Timezone is safe;
    • a tz can be de-initialized without causing segfault
    • a datetime with a de-initialized Timezone is still valid, i.e. UTC offset is still correct, can be converted to another tz etc. - at least if the Timezone was declared as 'const'.

@FObersteiner FObersteiner self-assigned this Oct 25, 2024
@FObersteiner FObersteiner marked this pull request as ready for review October 27, 2024 16:32
Comment on lines 61 to 76
test "tz deinit is mem-safe" {
var tzinfo = try Tz.fromTzdata("Asia/Tokyo", testing.allocator);
const dt = try Datetime.fromFields(.{ .year = 2027, .tz_options = .{ .tz = &tzinfo } });
tzinfo.deinit();

try testing.expectEqualStrings("", dt.tzName());
try testing.expectEqualStrings("JST", dt.tzAbbreviation());

// FIXME :
// // having tz be something else does not alter the datetime:
// tzinfo = try Tz.fromTzdata("Asia/Kolkata", testing.allocator);
// defer tzinfo.deinit();
// try testing.expectEqualStrings("JST", dt.tzAbbreviation());
// try testing.expectEqualStrings("", dt.tzName());
}

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uncomment the lines; looks like we created a new footgun

@FObersteiner FObersteiner merged commit 4d014a5 into master Oct 27, 2024
4 checks passed
@FObersteiner FObersteiner deleted the dev-ptrtz branch October 27, 2024 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant