paristemi
[ class tree: paristemi ] [ index: paristemi ] [ all elements ]

Source for file util_datetime.php

Documentation is available at util_datetime.php

  1. <?php
  2. /**
  3. * <b>Utility Class : Date & Time</b><br />
  4. * A collection of utility functions for working with date and time.
  5. * Most of the functions have to do with date formatting.
  6. * @author Kristen O'Brien <kristen_paristemi-com>
  7. * @copyright Copyright 2004, Kristen O'Brien
  8. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  9. * @link http://www.paristemi.com Paristemi Main Site
  10. * @package paristemi
  11. * @subpackage paristemi_util
  12. * @since Build 0.7
  13. * @version Build 0.7
  14. * @filesource
  15. */
  16. /**
  17. * Include the constants file and all of the files in the include list
  18. */
  19. if(ltrim(dirname($_SERVER['SCRIPT_FILENAME'])) == "" || !file_exists($_SERVER['DOCUMENT_ROOT']."/constants.php")) {
  20. if(!file_exists("../constants.php")) { require_once("../public_html/constants.php"); }
  21. else { require_once("../constants.php"); }
  22. }
  23. else { require_once($_SERVER['DOCUMENT_ROOT']."/constants.php"); }
  24.  
  25. /**
  26. * Utility Class : Date & Time
  27. * A collection of utility functions for working with date and time.
  28. * Most of the functions have to do with date formatting.
  29. * @author Kristen O'Brien <kristen_paristemi-com>
  30. * @copyright Copyright &copy; 2004, Kristen O'Brien
  31. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  32. * @link http://www.paristemi.com Paristemi Main Site
  33. * @package paristemi
  34. * @subpackage paristemi_util
  35. * @since Build 0.7
  36. * @version Build 0.7
  37. * @filesource
  38. */
  39. class UtilDatetime {
  40. // Helper functions for stored database data
  41. function FormatPHPDate(&$date,$showtime=1,$showweekday=1,$showyear=1) {
  42. $min = $date['minutes'] < 10 ? "0".$date['minutes'] : $date['minutes'];
  43. if($date['hours'] > 12) { $hours = ($date['hours']-12).":".$min." PM"; }
  44. else if($date['hours'] == 12) { $hours = $date['hours'].":".$min." PM"; }
  45. else { $hours = $date['hours'].":".$min." AM"; }
  46. $string = "";
  47. if($showweekday) { $string .= $date['weekday'].", "; }
  48. $string .= $date['month']." ".$date['mday'];
  49. if($showyear) { $string .= ", ".$date['year']; }
  50. if($showtime) { $string .= " - ".$hours; }
  51. return $string;
  52. }
  53. // Helper functions for stored database data
  54. function FormatShortPHPDate(&$date,$showtime=1,$showday=1) {
  55. $min = $date['minutes'] < 10 ? "0".$date['minutes'] : $date['minutes'];
  56. if($date['hours'] > 12) { $hours = ($date['hours']-12).":".$min." PM"; }
  57. else if($date['hours'] == 12) { $hours = $date['hours'].":".$min." PM"; }
  58. else { $hours = $date['hours'].":".$min." AM"; }
  59. $hours = $date['hours'] < 10 ? "0".$hours : $hours;
  60. $string = "";
  61. if($showday) { $string .= $date['mon']."/".$date['mday']."/".$date['year']; }
  62. if($showday && $showtime) { $string .= " - "; }
  63. if($showtime) { $string .= $hours; }
  64. return $string;
  65. }
  66. function FormatPHPDateToSQL($date) {
  67. return $date['year']."-".$date['mon']."-".$date['mday']
  68. ." ".$date['hours'].":".$date['minutes'].":".$date['seconds'];
  69. }
  70. }
  71. ?>

Documentation generated on Mon, 10 May 2004 12:11:07 -0700 by phpDocumentor 1.3.0RC3