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

Date math between DST is wrong #46

Open
smith153 opened this issue Mar 13, 2020 · 1 comment
Open

Date math between DST is wrong #46

smith153 opened this issue Mar 13, 2020 · 1 comment

Comments

@smith153
Copy link
Collaborator

This code:

use Time::Piece;
use Time::Seconds;

my $t = localtime(1583731856);

print "Current date: $t with hour offset: " . $t->tzoffset / 60 / 60 . "\n";
my $t2 = $t - ONE_DAY;

print "Minus 24 hours is: $t2 with hour offset: " . $t2->tzoffset / 60 / 60 . "\n";

Outputs this:

Current date: Mon Mar  9 00:30:56 2020 with hour offset: -5
Minus 24 hours is: Sat Mar  7 23:30:56 2020 with hour offset: -6

The correct date should be "Sun Mar 8 00:30:56 2020". The problem is there are only 23 hours in that day and we are subtracting 24.

@targzeta
Copy link

targzeta commented Nov 2, 2022

I can confirm this issue

use Time::Piece;

my $t1 = localtime(1667080800);
my $t2 = $t1 + Time::Seconds::ONE_DAY;

print "T1: $t1\nT2: $t2\n";

Output:

T1: Sun Oct 30 00:00:00 2022
T2: Sun Oct 30 23:00:00 2022

T2 should be Mon Oct 31 00:00:00 2022.

On the Sun Oct 30 at the 03:00 AM we have moved the clock back of one hour so the day has been 25 hours. How can be fix this issue?

Thank you in advance,
Emanuele

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

No branches or pull requests

2 participants