const dateByWeekNumber = (year, week) => {
// Cоздаём дату, гарантированно входящую в первую неделю.
const date = new Date(year, 0, 7);
// Откатываемся до первого четверга года
// По ГОСТ ИСО 8601-2001 первая неделя года должна содержать четверг
date.setDate(date.getDate() - (date.getDay() + 10) % 7);
// Переходим в нужную неделю
date.setDate(date.getDate() + (week - 1) * 7);
// Откатываемся до понедельника
date.setDate(date.getDate() - 3);
return date;
};
dateByWeekNumber(2023, 10);
// Date Mon Mar 06 2023 00:00:00 GMT+0300 (Москва, стандартное время)
dateByWeekNumber(2020, 1);
// Date Mon Dec 30 2019 00:00:00 GMT+0300 (Москва, стандартное время)
The special area of "Etc" is used for some administrative zones, particularly for "Etc/UTC" which represents Coordinated Universal Time. In order to conform with the POSIX style, those zone names beginning with "Etc/GMT" have their sign reversed from the standard ISO 8601 convention. In the "Etc" area, zones west of GMT have a positive sign and those east have a negative sign in their name (e.g "Etc/GMT-14" is 14 hours ahead of GMT)https://en.wikipedia.org/wiki/Tz_database#Area
const date = new Date(1647367200 * 1000);
console.log(date); // Date Tue Mar 15 2022 21:00:00 GMT+0300 (Москва, стандартное время)
const date1 = new Date(1647378000 * 1000)
console.log(date1); // Date Wed Mar 16 2022 00:00:00 GMT+0300 (Москва, стандартное время)
$dateTime = new DateTime('2021-05-18T15:30:00.000-04:00');
var_dump($dateTime);
$dateTime->setTimezone(new DateTimeZone('Europe/Moscow'));
var_dump($dateTime);
// object(DateTime)#1 (3) {
// ["date"] => string(26) "2021-05-18 15:30:00.000000"
// ["timezone_type"] => int(1)
// ["timezone"] => string(6) "-04:00"
// }
//object(DateTime)#1 (3) {
// ["date"] => string(26) "2021-05-18 22:30:00.000000"
// ["timezone_type"] => int(3)
// ["timezone"] => string(13) "Europe/Moscow"
//}
$timestamp = strtotime('2021-05-18T15:30:00.000-04:00');
var_dump($timestamp); // int(1621366200)
date_default_timezone_set('Europe/Moscow');
$dateTime = date('c', $timestamp);
var_dump($dateTime); // string(25) "2021-05-18T22:30:00+03:00"
function getFreeInterval($intervals, $startTime, $endTime)
{
$result = [];
$ok = false;
foreach($intervals as $key => $interval){
list($start, $end) = explode('-', $interval);
if ($startTime >= $start && $endTime <= $end) {
$ok = true;
if ($startTime > $start) {
$result[] = "{$start}-{$startTime}";
}
if ($endTime < $end) {
$result[] = "{$endTime}-{$end}";
}
} else {
$result[] = $interval;
}
}
return [
$ok,
$result
];
}
$intervals = [
'09:30:00-13:15:00',
'14:00:00-17:00:00'
];
list($ok, $result) = getFreeInterval($intervals, '09:30:00', '10:15:00');
var_dump($ok, $result);
// bool(true)
// array(2) {
// [0]=> string(17) "10:15:00-13:15:00"
// [1]=> string(17) "14:00:00-17:00:00"
// }
<?php
$begin = new DateTime('09:00');
$end = new DateTime('21:00');
$intervals = array(
array(new DateTime('10:00'), new DateTime('10:15')),
array(new DateTime('10:15'), new DateTime('11:45')),
array(new DateTime('12:30'), new DateTime('16:00'))
);
$time = 90;
function checkInterval($begin, $end, $time) {
$intervalDiff = $begin->diff($end);
$intervalMinutes = $intervalDiff->h * 60 + $intervalDiff->i;
if ($intervalMinutes >= $time) {
echo $begin->format('H:i'), ' - ', $end->format('H:i'), "\n";
}
}
$intervalStart = $begin;
foreach ($intervals as $interval) {
checkInterval($intervalStart, $interval[0], $time);
$intervalStart = $interval[1];
}
checkInterval($intervalStart, $end, $time);