squirrelmail-webmail  1.4.22
About: SquirrelMail is a standards-based webmail package with strong MIME support, address books, and folder manipulation (written in PHP4).
  Fossies Dox: squirrelmail-webmail-1.4.22.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

date.php
Go to the documentation of this file.
1 <?php
2 
19 require_once(SM_PATH . 'functions/constants.php');
20 
28 function getGMTSeconds($stamp, $tzc) {
29  /* date couldn't be parsed */
30  if ($stamp == -1) {
31  return -1;
32  }
33  /* timezone correction, expressed as `shhmm' */
34  switch($tzc)
35  {
36  case 'Pacific':
37  case 'PST':
38  $tzc = '-0800';
39  break;
40  case 'Mountain':
41  case 'MST':
42  case 'PDT':
43  $tzc = '-0700';
44  break;
45  case 'Central':
46  case 'CST':
47  case 'MDT':
48  $tzc = '-0600';
49  break;
50  case 'Eastern':
51  case 'EST':
52  case 'CDT':
53  $tzc = '-0500';
54  break;
55  case 'EDT':
56  $tzc = '-0400';
57  break;
58  case 'GMT':
59  $tzc = '+0000';
60  break;
61  case 'BST':
62  case 'MET':
63  case 'CET':
64  $tzc = '+0100';
65  break;
66  case 'EET':
67  case 'IST':
68  case 'MET DST':
69  case 'METDST':
70  case 'CEST':
71  case 'MEST':
72  $tzc = '+0200';
73  break;
74  case 'HKT':
75  $tzc = '+0800';
76  break;
77  case 'JST':
78  case 'KST':
79  $tzc = '+0900';
80  break;
81  }
82  $neg = false;
83  if (substr($tzc, 0, 1) == '-') {
84  $neg = true;
85  } else if (substr($tzc, 0, 1) != '+') {
86  $tzc = '+'.$tzc;
87  }
88  $hh = substr($tzc,1,2);
89  $mm = substr($tzc,3,2);
90  $iTzc = ($hh * 60 + $mm) * 60;
91  if ($neg) $iTzc = -1 * (int) $iTzc;
92  /* stamp in gmt */
93  $stamp -= $iTzc;
95  $current = date('Z', time());
96  /* stamp in local timezone */
97  $stamp += $current;
98 
99  return $stamp;
100 }
101 
112 function getDayName( $day_number ) {
113 
114  switch( $day_number ) {
115  case 0:
116  $ret = _("Sunday");
117  break;
118  case 1:
119  $ret = _("Monday");
120  break;
121  case 2:
122  $ret = _("Tuesday");
123  break;
124  case 3:
125  $ret = _("Wednesday");
126  break;
127  case 4:
128  $ret = _("Thursday");
129  break;
130  case 5:
131  $ret = _("Friday");
132  break;
133  case 6:
134  $ret = _("Saturday");
135  break;
136  default:
137  $ret = '';
138  }
139  return( $ret );
140 }
141 
147 function getDayAbrv( $day_number ) {
148 
149  switch( $day_number ) {
150  case 0:
151  $ret = _("Sun");
152  break;
153  case 1:
154  $ret = _("Mon");
155  break;
156  case 2:
157  $ret = _("Tue");
158  break;
159  case 3:
160  $ret = _("Wed");
161  break;
162  case 4:
163  $ret = _("Thu");
164  break;
165  case 5:
166  $ret = _("Fri");
167  break;
168  case 6:
169  $ret = _("Sat");
170  break;
171  default:
172  $ret = '';
173  }
174  return( $ret );
175 }
176 
177 
184 function getMonthName( $month_number ) {
185  switch( $month_number ) {
186  case '01':
187  $ret = _("January");
188  break;
189  case '02':
190  $ret = _("February");
191  break;
192  case '03':
193  $ret = _("March");
194  break;
195  case '04':
196  $ret = _("April");
197  break;
198  case '05':
199  $ret = _("May");
200  break;
201  case '06':
202  $ret = _("June");
203  break;
204  case '07':
205  $ret = _("July");
206  break;
207  case '08':
208  $ret = _("August");
209  break;
210  case '09':
211  $ret = _("September");
212  break;
213  case '10':
214  $ret = _("October");
215  break;
216  case '11':
217  $ret = _("November");
218  break;
219  case '12':
220  $ret = _("December");
221  break;
222  default:
223  $ret = '';
224  }
225  return( $ret );
226 }
227 
235 function getMonthAbrv( $month_number ) {
236  switch( $month_number ) {
237  case '01':
238  $ret = _("Jan");
239  break;
240  case '02':
241  $ret = _("Feb");
242  break;
243  case '03':
244  $ret = _("Mar");
245  break;
246  case '04':
247  $ret = _("Apr");
248  break;
249  case '05':
250  $ret = _("Ma&#121;");
251  break;
252  case '06':
253  $ret = _("Jun");
254  break;
255  case '07':
256  $ret = _("Jul");
257  break;
258  case '08':
259  $ret = _("Aug");
260  break;
261  case '09':
262  $ret = _("Sep");
263  break;
264  case '10':
265  $ret = _("Oct");
266  break;
267  case '11':
268  $ret = _("Nov");
269  break;
270  case '12':
271  $ret = _("Dec");
272  break;
273  default:
274  $ret = '';
275  }
276  return( $ret );
277 }
278 
286 function date_intl( $date_format, $stamp ) {
287  $ret = str_replace( array('D','F','l','M'), array('$1','$2','$3','$4'), $date_format );
288  // to reduce the date calls we retrieve m and w in the same call
289  $ret = date('w#m#'. $ret, $stamp );
290  // extract day and month in order to replace later by intl day and month
291  $aParts = explode('#',$ret);
292  $ret = str_replace(array('$1','$4','$2','$3',), array(getDayAbrv($aParts[0]),
293  getMonthAbrv($aParts[1]),
294  getMonthName($aParts[1]),
295  getDayName($aParts[0])),
296  $aParts[2]);
297  return( $ret );
298 }
299 
309 function getLongDateString( $stamp, $fallback = '' ) {
310 
311  global $hour_format;
312 
313  if ($stamp == -1) {
314  return $fallback;
315  }
316 
317  if ( $hour_format == SMPREF_TIME_12HR ) {
318  $date_format = _("D, F j, Y g:i a");
319  } else {
320  $date_format = _("D, F j, Y H:i");
321  }
322 
323  return( date_intl( $date_format, $stamp ) );
324 
325 }
326 
337 function getDateString( $stamp ) {
338 
340 
341  if ( $stamp == -1 ) {
342  return '';
343  }
344 
345  $now = time();
346 
347  $dateZ = date('Z', $now );
348 
349  // FIXME: isn't this obsolete and introduced as a terrible workaround
350  // for bugs at other places which are fixed a long time ago?
351  if ($invert_time) {
352  $dateZ = - $dateZ;
353  }
354 
355  // calculate when it was midnight and when it will be,
356  // in order to display dates differently if they're 'today'
357  $midnight = $now - ($now % 86400) - $dateZ;
358  // this is to correct if after calculations midnight is more than
359  // one whole day away.
360  if ($now - $midnight > 86400) {
361  $midnight += 86400;
362  }
363  $nextmid = $midnight + 86400;
364 
365  if (($show_full_date == 1) || ($nextmid < $stamp)) {
366  $date_format = _("M j, Y");
367  } else if ($midnight < $stamp) {
368  /* Today */
369  if ( $hour_format == SMPREF_TIME_12HR ) {
370  $date_format = _("g:i a");
371  } else {
372  $date_format = _("H:i");
373  }
374  } else if ($midnight - 518400 < $stamp) {
375  /* This week */
376  if ( $hour_format == SMPREF_TIME_12HR ) {
377  $date_format = _("D, g:i a");
378  } else {
379  $date_format = _("D, H:i");
380  }
381  } else {
382  /* before this week */
383  $date_format = _("M j, Y");
384  }
385 
386  return( date_intl( $date_format, $stamp ) );
387 }
388 
395 function getTimeStamp($dateParts) {
408  if (count($dateParts) <2) {
409  return -1;
410  } else if (count($dateParts) ==3) {
411  if (substr_count($dateParts[0],'-') == 2 &&
412  substr_count($dateParts[1],':') == 2) {
413  // dd-Month-yyyy 23:19:05 +0200
414  // redefine the date
415  $aDate = explode('-',$dateParts[0]);
416  $newDate = array($aDate[0],$aDate[1],$aDate[2],$dateParts[1],$dateParts[2]);
417  $dateParts = $newDate;
418  }
419  }
420 
421  /*
422  * Simply check to see if the first element in the dateParts
423  * array is an integer or not.
424  * Since the day of week is optional, this check is needed.
425  */
426  if (!is_numeric(trim($dateParts[0]))) {
427  /* cope with broken mailers that send "Tue,23" without space */
428  if ( preg_match ('/^\w+,(\d{1,2})$/', $dateParts[0], $match) ) {
429  /* replace Tue,23 with 23 */
430  $dateParts[0] = $match[1];
431  } else {
432  /* just drop the day of the week */
433  array_shift($dateParts);
434  }
435  }
436  /* calculate timestamp separated from the zone and obs-zone */
437  $stamp = strtotime(implode (' ', array_splice ($dateParts,0,4)));
438  if (!isset($dateParts[0])) {
439  $dateParts[0] = '+0000';
440  }
441 
442  if (!preg_match('/^[+-]{1}[0-9]{4}$/',$dateParts[0])) {
443  /* zone in obs-zone format */
444  if (preg_match('/\((.+)\)/',$dateParts[0],$regs)) {
445  $obs_zone = $regs[1];
446  } else {
447  $obs_zone = $dateParts[0];
448  }
449  return getGMTSeconds($stamp, $obs_zone);
450  } else {
451  return getGMTSeconds($stamp, $dateParts[0]);
452  }
453 }
454 
455 /* I use this function for profiling. Should never be called in
456  actual versions of squirrelmail released to public. */
457 /*
458  function getmicrotime() {
459  $mtime = microtime();
460  $mtime = explode(' ',$mtime);
461  $mtime = $mtime[1] + $mtime[0];
462  return ($mtime);
463  }
464 */
$ret
$ret
Definition: webmail.php:172
$show_full_date
$show_full_date
Definition: load_prefs.php:279
getDayName
getDayName( $day_number)
Definition: date.php:112
date_intl
date_intl( $date_format, $stamp)
Definition: date.php:286
getDayAbrv
getDayAbrv( $day_number)
Definition: date.php:147
getGMTSeconds
getGMTSeconds($stamp, $tzc)
Definition: date.php:28
getMonthAbrv
getMonthAbrv( $month_number)
Definition: date.php:235
$invert_time
$invert_time
Definition: config_default.php:129
getLongDateString
getLongDateString( $stamp, $fallback='')
Definition: date.php:309
getMonthName
getMonthName( $month_number)
Definition: date.php:184
SM_PATH
const SM_PATH
Definition: decrypt_headers.php:16
getDateString
getDateString( $stamp)
Definition: date.php:337
_
_($str)
Definition: gettext.php:160
SMPREF_TIME_12HR
const SMPREF_TIME_12HR
Definition: constants.php:49
$date_format
$date_format
Definition: load_prefs.php:247
getTimeStamp
getTimeStamp($dateParts)
Definition: date.php:395
$hour_format
$hour_format
Definition: load_prefs.php:248