diff options
author | jwangen <jwangen> | 2002-10-19 17:48:06 +0000 |
---|---|---|
committer | jwangen <jwangen> | 2002-10-19 17:48:06 +0000 |
commit | ddf26689cb100abb66976c08ee9723de6f394208 (patch) | |
tree | 014054df503e2875f6b8b5f78fed21daa9878ab3 /functions/date_functions.php | |
parent | 84ca808048ec2e9df83be7d0205536872b526e92 (diff) | |
download | phpicalendar-ddf26689cb100abb66976c08ee9723de6f394208.tar.gz phpicalendar-ddf26689cb100abb66976c08ee9723de6f394208.tar.bz2 phpicalendar-ddf26689cb100abb66976c08ee9723de6f394208.zip |
Timezone support added, fixed Oct 27 bug
Diffstat (limited to 'functions/date_functions.php')
-rw-r--r-- | functions/date_functions.php | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/functions/date_functions.php b/functions/date_functions.php index 418c769..2f73543 100644 --- a/functions/date_functions.php +++ b/functions/date_functions.php @@ -1 +1 @@ -<?php
// date_functions.php
// functions for returning or comparing dates
// takes Apple's 2 character day format and makes it into 3 characters
function two2threeCharDays($day) {
if ($day == "SU") $day_longer = "sun";
elseif ($day == "MO") $day_longer = "mon";
elseif ($day == "TU") $day_longer = "tue";
elseif ($day == "WE") $day_longer = "wed";
elseif ($day == "TH") $day_longer = "thu";
elseif ($day == "FR") $day_longer = "fri";
elseif ($day == "SA") $day_longer = "sat";
return $day_longer;
}
// dateOfWeek() takes a date in Ymd and a day of week in 3 letters or more
// and returns the date of that day. (ie: "sun" or "sunday" would be acceptable values of $day but not "su")
function dateOfWeek($Ymd, $day) {
global $week_start_day;
if (!isset($week_start_day)) $week_start_day = "Sunday";
$timestamp = strtotime($Ymd);
//$timestamp = strtotime("+1 day", $timestamp);
$num = date("w", strtotime($week_start_day));
//print $num;
//print date("w",$timestamp).' - ';
$start_day_time = strtotime((date("w",$timestamp)==$num ? "$week_start_day" : "last $week_start_day"), $timestamp);
// $start_day_time = strtotime('+1 day', $start_day_time);
//$start_day_time = date('I', $start_day_time)==1 ? $start_day_time : strtotime('+1 day', $start_day_time);
//print date('Y-m-d ', $start_day_time);
return date("Ymd",strtotime($day,$start_day_time));
}
// function to compare to dates in Ymd and return the number of weeks
// that differ between them. requires dateOfWeek()
function weekCompare($now, $then) {
global $week_start_day;
$sun_now = dateOfWeek($now, $week_start_day);
$sun_then = dateOfWeek($then, $week_start_day);
$seconds_now = strtotime($sun_now);
$seconds_then = strtotime($sun_then);
$diff_seconds = $seconds_now - $seconds_then;
$diff_minutes = $diff_seconds/60;
$diff_hours = $diff_minutes/60;
$diff_days = round($diff_hours/24);
$diff_weeks = $diff_days/7;
return $diff_weeks;
}
// function to compare to dates in Ymd and return the number of days
// that differ between them.
function dayCompare($now, $then) {
$seconds_now = strtotime($now);
$seconds_then = strtotime($then);
$diff_seconds = $seconds_now - $seconds_then;
$diff_minutes = $diff_seconds/60;
$diff_hours = $diff_minutes/60;
$diff_days = round($diff_hours/24);
return $diff_days;
}
// function to compare to dates in Ymd and return the number of months
// that differ between them.
function monthCompare($now, $then) {
ereg ("([0-9]{4})([0-9]{2})([0-9]{2})", $now, $date_now);
ereg ("([0-9]{4})([0-9]{2})([0-9]{2})", $then, $date_then);
$diff_years = $date_now[1] - $date_then[1];
$diff_months = $date_now[2] - $date_then[2];
if ($date_now[2] < $date_then[2]) {
$diff_years -= 1;
$diff_months = ($diff_months + 12) % 12;
}
$diff_months = ($diff_years * 12) + $diff_months;
return $diff_months;
}
function yearCompare($now, $then) {
ereg ("([0-9]{4})([0-9]{2})([0-9]{2})", $now, $date_now);
ereg ("([0-9]{4})([0-9]{2})([0-9]{2})", $then, $date_then);
$diff_years = $date_now[1] - $date_then[1];
return $diff_years;
}
// localizeDate() - similar to strftime but uses our preset arrays of localized
// months and week days and only supports %A, %a, %B, %b, %e, and %Y
// more can be added as needed but trying to keep it small while we can
function localizeDate($format, $timestamp) {
global $daysofweek_lang, $daysofweekshort_lang, $daysofweekreallyshort_lang, $monthsofyear_lang, $monthsofyear_lang, $monthsofyearshort_lang;
$year = date("Y", $timestamp);
$month = date("n", $timestamp)-1;
$day = date("j", $timestamp);
$dayofweek = date("w", $timestamp);
$date = str_replace('%Y', $year, $format);
$date = str_replace('%e', $day, $date);
$date = str_replace('%B', $monthsofyear_lang[$month], $date);
$date = str_replace('%b', $monthsofyearshort_lang[$month], $date);
$date = str_replace('%A', $daysofweek_lang[$dayofweek], $date);
$date = str_replace('%a', $daysofweekshort_lang[$dayofweek], $date);
return $date;
}
?>
\ No newline at end of file +<?php
// date_functions.php
// functions for returning or comparing dates
// takes Apple's 2 character day format and makes it into 3 characters
function two2threeCharDays($day) {
switch($day) {
case 'SU': $day_longer = 'sun'; break;
case 'MO': $day_longer = 'mon'; break;
case 'TU': $day_longer = 'tue'; break;
case 'WE': $day_longer = 'wed'; break;
case 'TH': $day_longer = 'thu'; break;
case 'FR': $day_longer = 'fri'; break;
case 'SA': $day_longer = 'sat'; break;
}
return $day_longer;
}
// dateOfWeek() takes a date in Ymd and a day of week in 3 letters or more
// and returns the date of that day. (ie: "sun" or "sunday" would be acceptable values of $day but not "su")
function dateOfWeek($Ymd, $day) {
global $week_start_day;
if (!isset($week_start_day)) $week_start_day = 'Sunday';
$timestamp = strtotime($Ymd);
$num = date('w', strtotime($week_start_day));
$start_day_time = strtotime((date('w',$timestamp)==$num ? "$week_start_day" : "last $week_start_day"), $timestamp);
$ret_unixtime = strtotime($day,$start_day_time);
$ret_unixtime = strtotime('+12 hours', $ret_unixtime);
$ret = date('Ymd',$ret_unixtime);
return $ret;
}
// function to compare to dates in Ymd and return the number of weeks
// that differ between them. requires dateOfWeek()
function weekCompare($now, $then) {
global $week_start_day;
$sun_now = dateOfWeek($now, $week_start_day);
$sun_then = dateOfWeek($then, $week_start_day);
$seconds_now = strtotime($sun_now);
$seconds_then = strtotime($sun_then);
$diff_seconds = $seconds_now - $seconds_then;
$diff_minutes = $diff_seconds/60;
$diff_hours = $diff_minutes/60;
$diff_days = round($diff_hours/24);
$diff_weeks = $diff_days/7;
return $diff_weeks;
}
// function to compare to dates in Ymd and return the number of days
// that differ between them.
function dayCompare($now, $then) {
$seconds_now = strtotime($now);
$seconds_then = strtotime($then);
$diff_seconds = $seconds_now - $seconds_then;
$diff_minutes = $diff_seconds/60;
$diff_hours = $diff_minutes/60;
$diff_days = round($diff_hours/24);
return $diff_days;
}
// function to compare to dates in Ymd and return the number of months
// that differ between them.
function monthCompare($now, $then) {
ereg ("([0-9]{4})([0-9]{2})([0-9]{2})", $now, $date_now);
ereg ("([0-9]{4})([0-9]{2})([0-9]{2})", $then, $date_then);
$diff_years = $date_now[1] - $date_then[1];
$diff_months = $date_now[2] - $date_then[2];
if ($date_now[2] < $date_then[2]) {
$diff_years -= 1;
$diff_months = ($diff_months + 12) % 12;
}
$diff_months = ($diff_years * 12) + $diff_months;
return $diff_months;
}
function yearCompare($now, $then) {
ereg ("([0-9]{4})([0-9]{2})([0-9]{2})", $now, $date_now);
ereg ("([0-9]{4})([0-9]{2})([0-9]{2})", $then, $date_then);
$diff_years = $date_now[1] - $date_then[1];
return $diff_years;
}
// localizeDate() - similar to strftime but uses our preset arrays of localized
// months and week days and only supports %A, %a, %B, %b, %e, and %Y
// more can be added as needed but trying to keep it small while we can
function localizeDate($format, $timestamp) {
global $daysofweek_lang, $daysofweekshort_lang, $daysofweekreallyshort_lang, $monthsofyear_lang, $monthsofyear_lang, $monthsofyearshort_lang;
$year = date("Y", $timestamp);
$month = date("n", $timestamp)-1;
$day = date("j", $timestamp);
$dayofweek = date("w", $timestamp);
$date = str_replace('%Y', $year, $format);
$date = str_replace('%e', $day, $date);
$date = str_replace('%B', $monthsofyear_lang[$month], $date);
$date = str_replace('%b', $monthsofyearshort_lang[$month], $date);
$date = str_replace('%A', $daysofweek_lang[$dayofweek], $date);
$date = str_replace('%a', $daysofweekshort_lang[$dayofweek], $date);
return $date;
}
// calcOffset takes an offset (ie, -0500) and returns it in the number of seconds
function calcOffset($offset_str) {
$sign = substr($offset_str, 0, 1);
$hours = substr($offset_str, 1, 2);
$mins = substr($offset_str, 3, 2);
$secs = ((int)$hours * 3600) + ((int)$mins * 60);
if ($sign == '-') $secs = 0 - $secs;
return $secs;
}
// calcTime calculates the unixtime of a new offset by comparing it to the current offset
// $have is the current offset (ie, '-0500')
// $want is the wanted offset (ie, '-0700')
// $time is the unixtime relative to $have
function calcTime($have, $want, $time) {
$have_secs = calcOffset($have);
$want_secs = calcOffset($want);
$diff = $want_secs - $have_secs;
$time += $diff;
return $time;
}
?>
\ No newline at end of file |