Comments (10)
Is there any mileage in doing some sort of "shortcut" before the timezone is added/calculated? E.g. if the day/month/year are off by so much that the timezone is irrelevant. Even something simple like if the years are different by more than 2 would work for our use case. Thanks.
from datetime.pm.
@abeverley - yes, that sort of fix could work. I think just checking if the year diff is >1 would be sufficient.
from datetime.pm.
@markov2 I'm not sure how one would decide when to start ignoring time zones. This really is something that users of the library are in a much better position to do than me as the library author.
from datetime.pm.
This actually isn't happening in DateTime.pm, it's because of how DateTime::TimeZone works. If the time zone has DST rules, then we need to calculate all the DST transitions until the timestamp for the DT.
This particular case is triggering the issue because when you compare a DT with a floating TZ to one without, it sets the DT with the floating TZ to the same TZ as the DT we're comparing against. Otherwise there's no way to compare the two.
It doesn't really make sense to use a time zone more than a few years in the future, as time zone rules change regularly. It definitely doesn't make sense to use them for dates that are decades away.
There is a warning if you try to create a far future DT with a non-UTC or floating TZ. I think it'd make sense to also warn in other cases that trigger this behavior, like the comparison case here.
from datetime.pm.
Do you really need to calculate time-zones when the years differ?
from datetime.pm.
Do you really need to calculate time-zones when the years differ?
Of course. If one TZ is at +12 and the other at -12 then you could easily have a case where the years differ but the one with a lower year is actually later in UTC.
from datetime.pm.
But then again, not if the years differ by more than 1. And indeed probably not if the ymd-part differs by 3 or more days :)
from datetime.pm.
But can you explain why, in above script $dt1 < $dt2
takes 7 seconds on my system, but $dt1->epoch < $dt2->epoch
less than one millisecond?
Wouldn't it simplify the code a lot when _compare()
would simple call epoch()
?
from datetime.pm.
But can you explain why, in above script $dt1 < $dt2 takes 7 seconds on my system, but $dt1->epoch < $dt2->epoch less than one millisecond?
I already did. It's because the DT in the floating time zone is converted to the time zone of the other DT, so it's equivalent to calling $dt1->clone->set_time_zone('Europe/London')->epoch < $dt2->epoch
.
from datetime.pm.
Certainly with an uncertain future of DST, wouldn't it be safe to simply ignore their existence for years to come? At least: until now, all DST effects have neutralized after the end of each year: no nett effect... it is only required to calculate the last year. Not all intermediate years.
(In our application, people can describe events will happen in the future (years). We do not want that to be inconveniently slow)
from datetime.pm.
Related Issues (20)
- Implement `use DateTime ':hires'` HOT 1
- Do I miss something with timezones? HOT 2
- Improve add_duration HOT 2
- Add ability to lock/unlock DateTime objects through methods, which when locked causes an exception on in-place modification HOT 2
- Have from_epoch() support just getting seconds passed HOT 6
- calculated last day of month wrong HOT 2
- -Inf/Inf should be formatted as -infinity/infinity HOT 8
- constructor will not accept second => 60 HOT 3
- Can not compare two datetime objects HOT 3
- DateTime->from_epoch( epoch => 0 ) HOT 5
- Tests fail when PERL_DATETIME_DEFAULT_TZ is set on system HOT 2
- Typos in recent Duration documentation update HOT 1
- datetime.perl.org not found HOT 1
- DateTime::Duration::in_units('days') should not return completely wrong answers for durations over 1 month HOT 19
- Truncate ignores DST flag. Bug or intended behavior? HOT 3
- Europe/Dublin DST flag is backwards? HOT 3
- Clarify pod "our $App::LocalTZ = ..." (not legal Perl syntax) HOT 1
- [Win32 quadmath] isfinite() does not accommodate __float128 HOT 11
- Sub::Identify not being detected as a prerequisite HOT 4
- Can't install `[email protected]` for `perl-5.10.1` on macOS 14 Sonoma HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from datetime.pm.