/[corp_html]/back/phormation/date_fcns.php
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /back/phormation/date_fcns.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Thu Feb 22 17:49:14 2001 UTC (23 years, 2 months ago) by dpavlin
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +9 -3 lines
support for euro dates dd.mm.yyyy

1 <?
2 /*
3 * Phormation
4 * - A library of PHP code to make development of database-driven
5 * html forms easy and quick
6 *
7 * Copyright (C) 2000 Jason D. Hildebrand
8 * PeaceWorks Computer Consulting
9 *
10 * jason@peaceworks.ca
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
25 */
26
27
28 $full_months = array( 1 => 'January',
29 2 => 'February',
30 3 => 'March',
31 4 => 'April',
32 5 => 'May',
33 6 => 'June',
34 7 => 'July',
35 8 => 'August',
36 9 => 'September',
37 10 => 'October',
38 11 => 'November',
39 12 => 'December' );
40
41 $short_months = array( 1 => 'Jan.',
42 2 => 'Feb.',
43 3 => 'Mar.',
44 4 => 'Apr.',
45 5 => 'May',
46 6 => 'June',
47 7 => 'July',
48 8 => 'Aug.',
49 9 => 'Sept.',
50 10 => 'Oct.',
51 11 => 'Nov.',
52 12 => 'Dec.' );
53
54 // parses a PostgreSQL date in format YYYY/MM/DD or YYYY-MM-DD
55 // into month, day, year components
56 function parse_date( $date ) {
57 $array["year"] = strtok( $date, "/-." );
58 $array["month"] = strtok( "/-." );
59 $array["day"] = strtok( "/-." );
60 // support euro style of dates dd.mm.yyyy
61 if ($array["day"] > 1900 && $array["year"] < 32) {
62 $foo=$array["year"];
63 $array["year"]=$array["day"];
64 $array["day"]=$foo;
65 }
66 return $array;
67 }
68
69 // outputs a month/day combo
70 function output_single_date( $date ) {
71 global $short_months;
72 $pdate = parse_date( $date );
73 echo $short_months[ (int) $pdate["month"] ] . " " . $pdate["day"];
74 }
75
76 // outputs a month/day range which makes sense to humans
77 function output_date_range( $startdate, $enddate ) {
78 global $short_months;
79 $pstartdate = parse_date( $startdate );
80 $penddate = parse_date( $enddate );
81
82 if( ((int)$pstartdate["month"]) == ((int)$penddate["month"]) ) {
83 echo $short_months[ (int)$pstartdate["month"] ] . " " . $pstartdate["day"] . "-" . $penddate["day"];
84 } else {
85 echo $short_months[ (int)$pstartdate["month"] ] . " " . $pstartdate["day"] . " - ";
86 echo $short_months[ (int)$penddate["month"] ] . " " . $penddate["day"];
87 }
88 }
89
90 ?>

  ViewVC Help
Powered by ViewVC 1.1.26