Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Lib.Date.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Set of usefull Date and Time functions
8  *
9  * @author Anakeen
10  * @version $Id: Lib.Date.php,v 1.2 2003/08/18 15:46:42 eric Exp $
11  * @package FDL
12  * @subpackage CORE
13  */
14 /**
15  */
16 // ---------------------------------------------------------------------------
17 // Date
18 // ---------------------------------------------------------------------------
19 // Anakeen 2000 - yannick.lebriquer@anakeen.com
20 // ---------------------------------------------------------------------------
21 // This program is free software; you can redistribute it and/or modify
22 // it under the terms of the GNU General Public License as published by
23 // the Free Software Foundation; either version 2 of the License, or (at
24 // your option) any later version.
25 //
26 // This program is distributed in the hope that it will be useful, but
27 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
28 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
29 // for more details.
30 //
31 // You should have received a copy of the GNU General Public License along
32 // with this program; if not, write to the Free Software Foundation, Inc.,
33 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 // ---------------------------------------------------------------------------
35 // $Id: Lib.Date.php,v 1.2 2003/08/18 15:46:42 eric Exp $
36 $LIB_DATE_PHP = '$Id: Lib.Date.php,v 1.2 2003/08/18 15:46:42 eric Exp $';
37 
38 function DayRound(&$timestamp)
39 {
40 
41  return mktime(0, 0, 0, strftime("%m", $timestamp) , strftime("%d", $timestamp) , strftime("%Y", $timestamp));
42 }
43 
44 function IncDay($timestamp, $inc)
45 {
46  return mktime(0, 0, 0, strftime("%m", $timestamp) , strftime("%d", $timestamp) + $inc, strftime("%Y", $timestamp));
47 }
48 // Return the next requested day
49 function GoNextWeekDay($now, $daynumber)
50 {
51  $inc = ($daynumber - strftime("%w", $now)) % 7;
52  return mktime(0, 0, 0, strftime("%m", $now) , strftime("%d", $now) + $inc, strftime("%Y", $now));
53 }
54 // Return the week first day as an epoch time
55 function FirstWeekDay($now)
56 {
57  $inc = (7 - strftime("%w", $now));
58  return mktime(0, 0, 0, strftime("%m", $now) , strftime("%d", $now) - $inc, strftime("%Y", $now));
59 }
60 /*
61 function UpdateFields() {
62  $this->year = strftime("%Y",$this->timestamp);
63  $this->monthnum = strftime("%m",$this->timestamp);
64  $this->lmonthstr = strftime("%B",$this->timestamp);
65  $this->smonthstr = strftime("%b",$this->timestamp);
66  $this->daynum = strftime("%d",$this->timestamp);
67  $this->ldaystr = strftime("%A",$this->timestamp);
68  $this->sdaystr = strftime("%a",$this->timestamp);
69  $this->hour = strftime("%H",$this->timestamp);
70  $this->minute = strftime("%M",$this->timestamp);
71  $this->second = strftime("%S",$this->timestamp);
72 }
73 */
74 // Return day count for a month
75 function daycount($m, $y)
76 {
77  return date("t", mktime(0, 0, 0, $m, 1, $y));
78 }
79 // Return the next day
80 function nextday($d, $m, $y, &$nd, &$nm, &$ny)
81 {
82  $nd = ($d == daycount($m, $y) ? 1 : $d + 1);
83  if ($nd == 1) nextmonth($m, $y, $nm, $ny);
84  else {
85  $nm = $m;
86  $ny = $y;
87  }
88 }
89 // Return the previous day
90 function prevday($d, $m, $y, &$pd, &$pm, &$py)
91 {
92  $pd = ($d == 1 ? daycount(($m - 1) , $y) : $d - 1);
93  if ($pd == daycount(($m - 1) , $y)) prevmonth($m, $y, $pm, $py);
94  else {
95  $pm = $m;
96  $py = $y;
97  }
98 }
99 // Return the next month
100 function nextmonth($m, $y, &$nm, &$ny)
101 {
102  $nm = ($m == 12 ? 1 : $m + 1);
103  $ny = ($nm == 1 ? $y + 1 : $y);
104 }
105 // Return the previous month
106 function prevmonth($m, $y, &$pm, &$py)
107 {
108  $pm = ($m == 1 ? 12 : $m - 1);
109  $py = ($pm == 12 ? $y - 1 : $y);
110 }
111 // Return the week number (weeks start on Monday)
112 function WeekNumber($epoch)
113 {
114  return strftime("%W", $epoch);
115 }
116 // Return the week first day as an epoch time
117 function GetWeekFirstDay($now, $epoch)
118 {
119 
120  return strftime("%W", $epoch);
121 }
122 ?>
nextday($d, $m, $y, &$nd, &$nm, &$ny)
Definition: Lib.Date.php:80
nextmonth($m, $y, &$nm, &$ny)
Definition: Lib.Date.php:100
GoNextWeekDay($now, $daynumber)
Definition: Lib.Date.php:49
$LIB_DATE_PHP
Definition: Lib.Date.php:36
daycount($m, $y)
Definition: Lib.Date.php:75
FirstWeekDay($now)
Definition: Lib.Date.php:55
IncDay($timestamp, $inc)
Definition: Lib.Date.php:44
$d
Definition: dav.php:77
GetWeekFirstDay($now, $epoch)
Definition: Lib.Date.php:117
DayRound(&$timestamp)
Definition: Lib.Date.php:38
prevday($d, $m, $y, &$pd, &$pm, &$py)
Definition: Lib.Date.php:90
prevmonth($m, $y, &$pm, &$py)
Definition: Lib.Date.php:106
WeekNumber($epoch)
Definition: Lib.Date.php:112
← centre documentaire © anakeen