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