Issue |
126476
|
Summary |
experimental chrono time zone support does not support DST changes when adding to local time
|
Labels |
new issue
|
Assignees |
|
Reporter |
pauljohnston2009
|
I've been using https://github.com/HowardHinnant/date for a while to handle time zones.
I've recently updated clang (19.1.7), and thought id switch out the date library for the std one.
I know the current features are still experimental, so this is possibly a known issue, though I could not find any similar issues.
I had to include "-fexperimental-library" compiler flags, so please close if this is a know issue, and not an oversight.
The issue is that a local time does not appear to be aware of its own timezone, so operations such as '+' do not work as expected.
tz->to_local() works fine, but trying to add to that (which crosses a DST change) does not consider the extra hour.
```
TEST(test_chrono_tz, london_dst_cross_add)
{
using namespace std::chrono_literals;
const auto tz = std::chrono::locate_zone("Europe/London");
ASSERT_TRUE(tz != nullptr);
// there is a DST change on March 30, 2025 for Europe/London
// changes from 1:00 am to 2:00 am
auto offset = 1h + 15min;
auto start_time = std::chrono::sys_days(2025y / 3 / 30);
auto utc_time_with_offset = start_time + offset;
auto local_time_with_offset = tz->to_local(utc_time_with_offset);
auto local_start_time = tz->to_local(start_time);
auto local_time_with_offset_added_after = local_start_time + offset;
EXPECT_EQ(local_time_with_offset, local_time_with_offset_added_after);
const char* expected = "2025-03-30 02:15:00";
EXPECT_EQ(expected, std::format("{:%F %T}", local_time_with_offset));
EXPECT_EQ(expected, std::format("{:%F %T}", local_time_with_offset_added_after));
}
```
results in
```
Expected equality of these values:
local_time_with_offset
Which is: 2025-03-30 02:15:00
local_time_with_offset_added_after
Which is: 2025-03-30 01:15:00
Expected equality of these values:
expected
Which is: "2025-03-30 02:15:00"
std::format("{:%F %T}", local_time_with_offset_added_after)
Which is: "2025-03-30 01:15:00"
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs