You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 1, 2023. It is now read-only.
You can use HH\Lib\Experimental\Time for this, but there are more valid values for it than actual time-as-read-from-a-clock. If you "abuse" HH\Lib\Experimental\Time to represent a time-as-read-from-a-clock, you end up having to use invariant_is_24h_clock_time() all over the place.
The vocabulary on HH\Lib\Experimental\Time makes it clear it is meant to be a duration, which makes the code read alien. You end up saying $x->isShorterThan($y), instead of $x->isBefore($y).
Here is a code snippet which shows what it is like to "abuse" HH\Lib\Experimental\Time for this purpose.
namespace_;
usenamespace HH\Lib\Experimental\DateTime;
usetype HH\Lib\Experimental\Time;
// Compares using an open range on the start time, but a closed range on the end time.// So if your workday starts at 8:30, then 8:30:00.000000 would be during your workday.// If you workday ends at 16:30, then 16:30.00.000000 would NOT be during your workday.functionis_during_work_hours(
DateTime\Zoned$dt,
Time$start_work_day,
Time$end_work_day,
): bool {
invariant_is_24h_clock_time($start_work_day);
invariant_is_24h_clock_time($end_work_day);
invariant(
$start_work_day->isShorter($end_work_day),
'Start work day (%s) must be before end work day (%s)',
$start_work_day->__toString(0),
$end_work_day->__toString(0),
);
$wall_time=Time::fromParts(...$dt->getTime());
return$wall_time->isLongerOrEqual($start_work_day) &&$wall_time->isShorter($end_work_day);
}
functioninvariant_is_24h_clock_time(Time$time): void {
invariant(
($time->isPositive() ||$time->isZero()) &&$time->getHours() <24,
'%s is not a valid time-as-read-from-a-clock',
$time->__toString(0),
);
}
<<__EntryPoint>>
functionmain(): void {
require_once__DIR__.'/vendor/autoload.hack';
\Facebook\AutoloadMap\initialize();
\var_dump(is_during_work_hours(
DateTime\Zoned::now(DateTime\Zone::AMERICA_LOS_ANGELES),
Time::fromParts(8, 30),
Time::fromParts(16, 30),
));
}
The text was updated successfully, but these errors were encountered:
You can use
HH\Lib\Experimental\Time
for this, but there are more valid values for it than actual time-as-read-from-a-clock. If you "abuse"HH\Lib\Experimental\Time
to represent a time-as-read-from-a-clock, you end up having to useinvariant_is_24h_clock_time()
all over the place.The vocabulary on
HH\Lib\Experimental\Time
makes it clear it is meant to be a duration, which makes the code read alien. You end up saying$x->isShorterThan($y)
, instead of$x->isBefore($y)
.Here is a code snippet which shows what it is like to "abuse"
HH\Lib\Experimental\Time
for this purpose.The text was updated successfully, but these errors were encountered: