JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
added code for 12 hour time formatting. Moved enc_mdy and format_ymd out of time.php
authorJason Woofenden <jason283@herkamire.com>
Fri, 6 Feb 2009 20:39:02 +0000 (15:39 -0500)
committerJason Woofenden <jason283@herkamire.com>
Fri, 6 Feb 2009 20:39:02 +0000 (15:39 -0500)
encode.php
format.php
time.php

index 6102a91..273d026 100644 (file)
@@ -161,6 +161,11 @@ function enc_mmddyyyy($yyyy_mm_dd) {
        return substr($yyyy_mm_dd, 5, 2) . '/' . substr($yyyy_mm_dd, 8, 2) . '/' . substr($yyyy_mm_dd, 0, 4);
 }
 
+# depricated. call enc_mmddyyyy() instead
+function enc_mdy($str) {
+       return enc_mmddyyyy($str);
+}
+
 function enc_mmddyyyyhhmm($seconds) {
        return date('m/d/Y g:ia', (int)$seconds);
 }
@@ -177,6 +182,26 @@ function enc_hhmm($str) {
        return $str;
 }
 
+# takes decimal
+# returns hh:mm followed by "am" or "pm" with no space
+function enc_12hr($str) {
+       if(strlen($str) == 0) {
+               return '';
+       }
+       $hours = floor($str);
+       $minutes = round(($str - $hours) * 60);
+       $suffix = 'am';
+       if($hours >= 12.0) {
+               $suffix = 'pm';
+               if($hours > 12.0) {
+                       $hours -= 12.0;
+               }
+       }
+       $str = sprintf("%d:%02d", $hours, $minutes);
+       $str .= $suffix;
+       return $str;
+}
+
 
 
 
index 8035be4..f90fc1f 100644 (file)
@@ -218,6 +218,13 @@ function format_mdy_to_ymd($str) {
        return mdy_to_ymd(format_oneline($str));
 }
 
+# date is yyyy-mm-dd
+function format_ymd($str) {
+       require_once('code/wfpl/time.php');
+       list($year, $month, $day) = ymd_clean($str);
+       return sprintf('%04u-%02u-%02u', $year, $month, $day);
+}
+
 # takes any of: HH  :MM  HH:MM
 # returns decimal number of hours
 #
@@ -253,6 +260,19 @@ function format_hours($str) {
        }
 }
 
+# takes eg 12:23am
+# returns decimal number of hours since midnight
+function format_12hr_to_hours($str) {
+       if(eregi('noon', $str)) {
+               return 12;
+       }
+       $hours = format_hours($str);
+       if($hours < 12 && eregi('p', $str)) {
+               $hours += 12;
+       }
+       return $hours;
+}
+
 
 function format_phone($str) {
        $str = ereg_replace('[^0-9]', '', $str);
index be2763e..3c42f79 100644 (file)
--- a/time.php
+++ b/time.php
@@ -18,6 +18,7 @@
 
 # This file contains functions to manipulate/calculate dates/times
 
+# FIXME make it so you can call this with a string YYYY-MM-DD
 function ymd_to_days($year, $month, $day) {
        return (int)(mktime(12,0,0,$month,$day, $year, 0) / 86400);
 }
@@ -135,12 +136,3 @@ function ymd_to_mdy($str) {
        list($year, $month, $day) = ymd_clean($str);
        return sprintf('%02u/%02u/%04u', $month, $day, $year);
 }
-
-function enc_mdy($str) {
-       return ymd_to_mdy($str);
-}
-
-function format_ymd($str) {
-       list($year, $month, $day) = ymd_clean($str);
-       return sprintf('%04u-%02u-%02u', $year, $month, $day);
-}