-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
Introduce a ZonedDateTimeRange #45
Comments
Should the end of this range be inclusive like in LoccalDateRange, or exclusive like in Interval? |
Related to #34 |
I don't have a strong opinion about this. Ideally it would stay consistent with other range concepts in the lib. Maybe @BenMorel could explain its reasoning on why it's different in the first place. |
I think the reason is that concept of inclusive duration is quite complicated when units become small.
How long $duration should be in this case? |
Any reason it shouldn't be |
Inclusion :) |
After some thinking I consider that duration in case when start = end should be 1 nanosec.
But working in this type of scale is quite tricky when you put this dates in query like this: Use exclusion type like Interval leads to different query |
I don't understand your point sorry, Since class ZonedDateTimeRange {
private function __construct(private ZonedDateTime $start, private ZonedDateTime $end)
{
}
public static function of(ZonedDateTime $start, ZonedDateTime $end)
{
return new self($start, $end);
}
public function getDuration(): Duration
{
return (new Interval($this->start->getInstant(), $this->end->getInstant()))->getDuration();
}
}
$zd = ZonedDateTime::parse('2020-01-01T15:16:20+01:00');
$zd2 = ZonedDateTime::parse('2020-01-01T15:16:20+01:00');
$duration = ZonedDateTimeRange::of($zd , $zd2);
echo $duration->getDuration()->getTotalNanos(); // 0 |
We've developed a package on top of Here's the latest version we have in our project, which has not yet been made available publicly (not yet had the time to update the public package...) : https://gist.github.com/gnutix/d730da3f5e3a9beedd62571418f62194 (class and tests, updated on 2024-03-23). And here's the (outdated) version available in the public repository : Some methods worth having a look at (in the latest version) are |
For those interested, I've updated the gist with the latest version of our code. A proper package will come, someday... |
Hello,
Interval
is a range of two instants andLocalDateRange
is not Zoned nor include time.However for cases where you need to schedule an event in the future (e.g. from
21/02/2022 10h00 Europe/Paris
to21/02/2022 12h00 Europe/Paris
) you want to keep the timezone to prevent timezone shifts.WDYT ?
The text was updated successfully, but these errors were encountered: