PHP code example of digital-craftsman / datetime-parts
1. Go to this page and download the library: Download digital-craftsman/datetime-parts library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
digital-craftsman / datetime-parts example snippets
$nowInFacility = $now->setTimezone($facilityTimeZone);
$openFrom = $nowInFacility->setTime(
(int) $facility->openFrom->format('H'),
(int) $facility->openFrom->format('i'),
);
if ($nowInFacility < $openFrom) {
throw new FacilityIsNotOpenYet();
}
if ($now->isBeforeInTimeZone($facility->openFrom, $facilityTimeZone)) {
throw new FacilityIsNotOpenYet();
}
$now = Moment::fromString('2026-03-29 07:30:00'); // UTC
$start = Moment::fromStringInTimeZone('2026-03-29 08:00', $berlin); // converted to UTC
$date = $now->dateInTimeZone($berlin); // Date
$time = $now->timeInTimeZone($berlin); // Time
$month = $now->monthInTimeZone($berlin); // Month
$now->isBeforeInTimeZone($facility->openFrom, $facilityTimeZone); // Time
$now->isBeforeInTimeZone($facility->earliestBookingDate, $facilityTimeZone); // Date
$now->isAfterInTimeZone($contract->lastMonth, $customerTimeZone); // Month
#[ORM\Entity]
class Facility
{
#[ORM\Column(type: Moment::class)]
public Moment $createdAt;
#[ORM\Column(type: Time::class)]
public Time $openFrom;
#[ORM\Column(type: Date::class)]
public Date $earliestBookingDate;
}
$now = $this->clock->now();
// In tests
$clock->freeze(Moment::fromString('2026-01-01 12:00:00'));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.