Added rest of translation pairs of systran.otenet.gr, besides greek pairs.
[squirrelmail.git] / functions / date.php
CommitLineData
59177427 1<?php
7350889b 2
35586184 3/**
4 * date.php
5 *
76911253 6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
35586184 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Takes a date and parses it into a usable format. The form that a
10 * date SHOULD arrive in is:
11 * <Tue,> 29 Jun 1999 09:52:11 -0500 (EDT)
12 * (as specified in RFC 822) -- 'Tue' is optional
13 *
14 * $Id$
15 */
16
b68edc75 17require_once(SM_PATH . 'functions/constants.php');
35586184 18
dc06f88c 19/* corrects a time stamp to be the local time */
d5c4ae7c 20function getGMTSeconds($stamp, $tzc) {
dc06f88c 21 /* date couldn't be parsed */
913ed9a3 22 if ($stamp == -1) {
23 return -1;
24 }
d5c4ae7c 25 /* timezone correction, expressed as `shhmm' */
26 switch($tzc)
dc06f88c 27 {
28 case 'Pacific':
29 case 'PST':
d5c4ae7c 30 $tzc = '-0800';
dc06f88c 31 break;
32 case 'Mountain':
33 case 'MST':
34 case 'PDT':
d5c4ae7c 35 $tzc = '-0700';
dc06f88c 36 break;
37 case 'Central':
38 case 'CST':
39 case 'MDT':
d5c4ae7c 40 $tzc = '-0600';
dc06f88c 41 break;
42 case 'Eastern':
43 case 'EST':
44 case 'CDT':
d5c4ae7c 45 $tzc = '-0500';
dc06f88c 46 break;
47 case 'EDT':
d5c4ae7c 48 $tzc = '-0400';
dc06f88c 49 break;
50 case 'GMT':
d5c4ae7c 51 $tzc = '+0000';
dc06f88c 52 break;
53 case 'BST':
d5c4ae7c 54 case 'MET':
55 case 'CET':
56 $tzc = '+0100';
57 break;
dc06f88c 58 case 'EET':
59 case 'IST':
60 case 'MET DST':
61 case 'METDST':
d5c4ae7c 62 $tzc = '+0200';
dc06f88c 63 break;
64 case 'HKT':
d5c4ae7c 65 $tzc = '+0800';
dc06f88c 66 break;
67 case 'JST':
68 case 'KST':
d5c4ae7c 69 $tzc = '+0900';
dc06f88c 70 break;
0e4ae91a 71 }
d5c4ae7c 72 $neg = false;
73 if (substr($tzc, 0, 1) == '-') {
0e4ae91a 74 $neg = true;
d5c4ae7c 75 } else if (substr($tzc, 0, 1) != '+') {
76 $tzc = '+'.$tzc;
0e4ae91a 77 }
d5c4ae7c 78 $hh = substr($tzc,1,2);
79 $mm = substr($tzc,3,2);
80 $iTzc = ($hh * 60 + $mm) * 60;
81 if ($neg) $iTzc = -1 * (int) $iTzc;
82 /* stamp in gmt */
83 $stamp -= $iTzc;
0e4ae91a 84 /** now find what the server is at **/
85 $current = date('Z', time());
d5c4ae7c 86 /* stamp in local timezone */
87 $stamp += $current;
0e4ae91a 88
89 return $stamp;
90}
0f1835f3 91
0e4ae91a 92/**
dc06f88c 93 Switch system has been intentionaly chosen for the
0e4ae91a 94 internationalization of month and day names. The reason
95 is to make sure that _("") strings will go into the
96 main po.
97**/
0f1835f3 98
0e4ae91a 99function getDayName( $day_number ) {
0f1835f3 100
0e4ae91a 101 switch( $day_number ) {
102 case 0:
103 $ret = _("Sunday");
104 break;
105 case 1:
106 $ret = _("Monday");
107 break;
108 case 2:
109 $ret = _("Tuesday");
110 break;
111 case 3:
112 $ret = _("Wednesday");
113 break;
114 case 4:
115 $ret = _("Thursday");
116 break;
117 case 5:
118 $ret = _("Friday");
119 break;
120 case 6:
121 $ret = _("Saturday");
122 break;
123 default:
124 $ret = '';
125 }
126 return( $ret );
127}
d59837cf 128
22d73941 129function getDayAbrv( $day_number ) {
130
131 switch( $day_number ) {
132 case 0:
133 $ret = _("Sun");
134 break;
135 case 1:
136 $ret = _("Mon");
137 break;
138 case 2:
139 $ret = _("Tue");
140 break;
141 case 3:
142 $ret = _("Wed");
143 break;
144 case 4:
145 $ret = _("Thu");
146 break;
147 case 5:
148 $ret = _("Fri");
149 break;
150 case 6:
151 $ret = _("Sat");
152 break;
153 default:
154 $ret = '';
155 }
156 return( $ret );
157}
158
0e4ae91a 159function getMonthName( $month_number ) {
160 switch( $month_number ) {
161 case '01':
162 $ret = _("January");
163 break;
164 case '02':
165 $ret = _("February");
166 break;
167 case '03':
168 $ret = _("March");
169 break;
170 case '04':
171 $ret = _("April");
172 break;
173 case '05':
174 $ret = _("May");
175 break;
176 case '06':
177 $ret = _("June");
178 break;
179 case '07':
180 $ret = _("July");
181 break;
182 case '08':
183 $ret = _("August");
184 break;
185 case '09':
186 $ret = _("September");
187 break;
188 case '10':
189 $ret = _("October");
190 break;
191 case '11':
192 $ret = _("November");
193 break;
194 case '12':
195 $ret = _("December");
196 break;
197 default:
198 $ret = '';
199 }
200 return( $ret );
201}
d59837cf 202
22d73941 203function getMonthAbrv( $month_number ) {
204 switch( $month_number ) {
205 case '01':
206 $ret = _("Jan");
207 break;
208 case '02':
209 $ret = _("Feb");
210 break;
211 case '03':
212 $ret = _("Mar");
213 break;
214 case '04':
215 $ret = _("Apr");
216 break;
217 case '05':
218 $ret = _("Ma&#121;");
219 break;
220 case '06':
221 $ret = _("Jun");
222 break;
223 case '07':
224 $ret = _("Jul");
225 break;
226 case '08':
227 $ret = _("Aug");
228 break;
229 case '09':
230 $ret = _("Sep");
231 break;
232 case '10':
233 $ret = _("Oct");
234 break;
235 case '11':
236 $ret = _("Nov");
237 break;
238 case '12':
239 $ret = _("Dec");
240 break;
241 default:
242 $ret = '';
243 }
244 return( $ret );
245}
246
247
0e4ae91a 248function date_intl( $date_format, $stamp ) {
e6b76811 249 $ret = str_replace( array('D','F','l','M'), array('$1','$2','$3','$4'), $date_format );
250 $ret = date('w#m#'. $ret, $stamp ); // to reduce the date calls we retrieve m and w in the same call
251 $aParts = explode('#',$ret); // extract day and month in order to replace later by intl day and month
252 $ret = str_replace(array('$1','$4','$2','$3',), array(getDayAbrv($aParts[0]),
15d49d77 253 getMonthAbrv($aParts[1]),
254 getMonthName($aParts[1]),
e6b76811 255 getDayName($aParts[0])),
256 $aParts[2]);
257 return( $ret );
0e4ae91a 258}
d59837cf 259
0e4ae91a 260function getLongDateString( $stamp ) {
d59837cf 261
0e4ae91a 262 global $hour_format;
263
913ed9a3 264 if ($stamp == -1) {
265 return '';
266 }
267
0e4ae91a 268 if ( $hour_format == SMPREF_TIME_12HR ) {
269 $date_format = _("D, F j, Y g:i a");
270 } else {
271 $date_format = _("D, F j, Y G:i");
272 }
273
274 return( date_intl( $date_format, $stamp ) );
0f1835f3 275
0e4ae91a 276}
d205a7bf 277
0e4ae91a 278function getDateString( $stamp ) {
d68a3926 279
3e3b60e3 280 global $invert_time, $hour_format, $show_full_date;
dc06f88c 281
282 if ( $stamp == -1 ) {
283 return '';
284 }
0e4ae91a 285
286 $now = time();
287
288 $dateZ = date('Z', $now );
289 if ($invert_time) {
290 $dateZ = - $dateZ;
291 }
292 $midnight = $now - ($now % 86400) - $dateZ;
7e27023f 293 $nextmid = $midnight + 86400;
0e4ae91a 294
7e27023f 295 if (($show_full_date == 1) || ($nextmid < $stamp)) {
3e3b60e3 296 $date_format = _("M j, Y");
297 } else if ($midnight < $stamp) {
0e4ae91a 298 /* Today */
299 if ( $hour_format == SMPREF_TIME_12HR ) {
300 $date_format = _("g:i a");
301 } else {
302 $date_format = _("G:i");
303 }
304 } else if ($midnight - 518400 < $stamp) {
305 /* This week */
306 if ( $hour_format == SMPREF_TIME_12HR ) {
307 $date_format = _("D, g:i a");
308 } else {
309 $date_format = _("D, G:i");
310 }
311 } else {
312 /* before this week */
313 $date_format = _("M j, Y");
314 }
315
316 return( date_intl( $date_format, $stamp ) );
317}
0f1835f3 318
0e4ae91a 319function getTimeStamp($dateParts) {
320 /** $dateParts[0] == <day of week> Mon, Tue, Wed
321 ** $dateParts[1] == <day of month> 23
322 ** $dateParts[2] == <month> Jan, Feb, Mar
323 ** $dateParts[3] == <year> 1999
324 ** $dateParts[4] == <time> 18:54:23 (HH:MM:SS)
325 ** $dateParts[5] == <from GMT> +0100
326 ** $dateParts[6] == <zone> (EDT)
327 **
328 ** NOTE: In RFC 822, it states that <day of week> is optional.
329 ** In that case, dateParts[0] would be the <day of month>
330 ** and everything would be bumped up one.
331 **/
d5c4ae7c 332
0e4ae91a 333 /*
334 * Simply check to see if the first element in the dateParts
335 * array is an integer or not.
dc06f88c 336 * Since the day of week is optional, this check is needed.
0e4ae91a 337 */
50457d45 338 if (count($dateParts) <2) {
339 return 0;
340 }
3302d0d4 341
d5c4ae7c 342 /* remove day of week */
343 if (!is_numeric(trim($dateParts[0]))) {
344 $dataParts = array_shift($dateParts);
0e4ae91a 345 }
d5c4ae7c 346 /* calculate timestamp separated from the zone and obs-zone */
347 $stamp = strtotime(implode (' ', array_splice ($dateParts,0,4)));
348 if (!isset($dateParts[0])) {
349 $dateParts[0] = '+0000';
0e4ae91a 350 }
dc06f88c 351
d5c4ae7c 352 if (!preg_match('/^[+-]{1}[0-9]{4}$/',$dateParts[0])) {
353 /* zone in obs-zone format */
354 if (preg_match('/\((.+)\)/',$dateParts[0],$regs)) {
355 $obs_zone = $regs[1];
356 } else {
357 $obs_zone = $dateParts[0];
358 }
359 return getGMTSeconds($stamp, $obs_zone);
360 } else {
361 return getGMTSeconds($stamp, $dateParts[0]);
0e4ae91a 362 }
0e4ae91a 363}
5e90d34a 364
0e4ae91a 365/* I use this function for profiling. Should never be called in
366 actual versions of squirrelmail released to public. */
d205a7bf 367/*
5e90d34a 368 function getmicrotime() {
369 $mtime = microtime();
b9bfd165 370 $mtime = explode(' ',$mtime);
5e90d34a 371 $mtime = $mtime[1] + $mtime[0];
372 return ($mtime);
9774bdef 373 }
d205a7bf 374*/
35586184 375?>