note 128133 added to class.intlcalendar
| From: | Doug at main dot php dot net | Date: | Fri, 20 Jan 2023 15:54:41 +0000 |
| Subject: | note 128133 added to class.intlcalendar | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-220088@lists.php.net to get a copy of this message | ||
Example obtaining a week and its boundaries (for building a calendar view):
<?php
$date = new DateTime('now');
$locale = 'en_US';
$thisWeek = IntlCalendar::fromDateTime($date, $locale);
$thisWeek->set(IntlCalendar::FIELD_DAY_OF_WEEK, $thisWeek->getFirstDayOfWeek());
// $thisWeek now points to the first day of the week
$weekStart = $thisWeek->toDateTime();
$daysToAdvance = $thisWeek->getMaximum(IntlCalendar::FIELD_DAY_OF_WEEK) - 1;
// Maximum number of days in a week minus 1 gets you to the last day
$weekEnd = $weekStart->modify("+{$daysToAdvance} days");
$previousWeek = IntlCalendar::fromDateTime($date, $locale);
$previousWeek->add(IntlCalendar::FIELD_WEEK_OF_YEAR, -1);
$previousWeek = $previousWeek->toDateTime();
$nextWeek = IntlCalendar::fromDateTime($date, $locale);
$nextWeek->add(IntlCalendar::FIELD_WEEK_OF_YEAR, 1);
$nextWeek = $nextWeek->toDateTime();
?>
----
Server IP: 45.112.84.4
Probable Submitter: 45.91.158.213 (proxied: 2804:fc:8d10:5400:1594:58b7:a056:d00e)
----
Manual Page -- https://php.net/manual/en/class.intlcalendar.php
Edit -- https://main.php.net/note/edit/128133
Del: integrated -- https://main.php.net/note/delete/128133/integrated
Del: useless -- https://main.php.net/note/delete/128133/useless
Del: bad code -- https://main.php.net/note/delete/128133/bad+code
Del: spam -- https://main.php.net/note/delete/128133/spam
Del: non-english -- https://main.php.net/note/delete/128133/non-english
Del: in docs -- https://main.php.net/note/delete/128133/in+docs
Del: other reasons-- https://main.php.net/note/delete/128133
Reject -- https://main.php.net/note/reject/128133
Search -- https://main.php.net/manage/user-notes.php