1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-14 10:52:41 +01:00
phorge-phorge/src/applications/conpherence/util/ConpherenceTimeUtil.php
Bob Trahan 03b1ecbcdd Conpherence - implement epoch creation slightly differently
Summary: D6114 fixed some bugs but on production it shows up as a new bug where Saturday is the first day? stop messing with the DateTime object so much and do some old school epoch manipulation. This works correctly on my laptop and my still fail in production, but it will rule out DateTime suckage.

Test Plan: still works on laptop

Reviewers: epriestley, chad

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D6115
2013-06-03 15:40:00 -07:00

60 lines
1.6 KiB
PHP

<?php
final class ConpherenceTimeUtil {
public static function getCalendarEventEpochs(
PhabricatorUser $user,
$start_day_str = 'Sunday') {
$objects = self::getStartDateTimeObjects($user, $start_day_str);
$start_day = $objects['start_day'];
$end_day = clone $start_day;
$end_day->modify('+9 days');
return array(
'start_epoch' => $start_day->format('U'),
'end_epoch' => $end_day->format('U'));
}
public static function getCalendarWidgetTimestamps(
PhabricatorUser $user,
$start_day_str = 'Sunday') {
$objects = self::getStartDateTimeObjects($user, $start_day_str);
$start_day = $objects['start_day'];
$timestamps = array();
for ($day = 0; $day < 9; $day++) {
$timestamp = clone $start_day;
$timestamp->modify(sprintf('+%d days', $day));
$timestamps[] = $timestamp;
}
return array(
'today' => $objects['today'],
'epoch_stamps' => $timestamps
);
}
private static function getStartDateTimeObjects(
PhabricatorUser $user,
$start_day_str) {
$timezone = new DateTimeZone($user->getTimezoneIdentifier());
$today_epoch = PhabricatorTime::parseLocalTime('today', $user);
$today = new DateTime('@'.$today_epoch);
$today->setTimeZone($timezone);
if ($today->format('l') == $start_day_str) {
$start_day = clone $today;
} else {
$start_epoch = PhabricatorTime::parseLocalTime(
'last '.$start_day_str,
$user);
$start_day = new DateTime('@'.$start_epoch);
$start_day->setTimeZone($timezone);
}
return array(
'today' => $today,
'start_day' => $start_day);
}
}