Subversion Repositories Applications.papyrus

Rev

Rev 1688 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1463 alexandre_ 1
<?php
2
// +----------------------------------------------------------------------+
3
// | PEAR :: I18Nv2 :: Locale                                             |
4
// +----------------------------------------------------------------------+
5
// | This source file is subject to version 3.0 of the PHP license,       |
6
// | that is available at http://www.php.net/license/3_0.txt              |
7
// | If you did not receive a copy of the PHP license and are unable      |
8
// | to obtain it through the world-wide-web, please send a note to       |
9
// | license@php.net so we can mail you a copy immediately.               |
10
// +----------------------------------------------------------------------+
11
// | Copyright (c) 2004 Michael Wallner <mike@iworks.at>                  |
12
// +----------------------------------------------------------------------+
13
//
14
// $Id: Locale.php,v 1.1 2007-06-25 09:55:28 alexandre_tb Exp $
15
 
16
/**
17
 * I18Nv2::Locale
18
 *
19
 * @package      I18Nv2
20
 * @category     Internationalisation
21
 */
22
 
23
/**#@+ Constants **/
24
define('I18Nv2_NUMBER',                     'number');
25
define('I18Nv2_CURRENCY',                   'currency');
26
define('I18Nv2_DATE',                       'date');
27
define('I18Nv2_TIME',                       'time');
28
define('I18Nv2_DATETIME',                   'datetime');
29
 
30
define('I18Nv2_NUMBER_FLOAT' ,              'float');
31
define('I18Nv2_NUMBER_INTEGER' ,            'integer');
32
 
33
define('I18Nv2_CURRENCY_LOCAL',             'local');
34
define('I18Nv2_CURRENCY_INTERNATIONAL',     'international');
35
 
36
define('I18Nv2_DATETIME_SHORT',             'short');
37
define('I18Nv2_DATETIME_DEFAULT',           'default');
38
define('I18Nv2_DATETIME_MEDIUM',            'medium');
39
define('I18Nv2_DATETIME_LONG',              'long');
40
define('I18Nv2_DATETIME_FULL',              'full');
41
/**#@-*/
42
 
43
require_once 'PEAR.php';
44
require_once 'I18Nv2.php';
45
 
46
/**
47
 * I18Nv2_Locale
48
 *
49
 * @author       Michael Wallner <mike@php.net>
50
 * @version      $Revision: 1.1 $
51
 * @access       public
52
 * @package      I18Nv2
53
 */
54
class I18Nv2_Locale
55
{
56
    /**
57
     * Initialized Locale
58
     *
59
     * @access  protected
60
     * @var     string
61
     */
62
    var $initialized = '';
63
 
64
    /**
65
     * Full day names
66
     *
67
     * @access  protected
68
     * @var     array
69
     */
70
    var $days = array();
71
 
72
    /**
73
     * Full month names
74
     *
75
     * @access  protected
76
     * @var     array
77
     */
78
    var $months = array();
79
 
80
    /**
81
     * Abbreviated day names
82
     *
83
     * @access  protected
84
     * @var     array
85
     */
86
    var $abbrDays = array();
87
 
88
    /**
89
     * Abbreviated month names
90
     *
91
     * @access  protected
92
     * @var     array
93
     */
94
    var $abbrMonths = array();
95
 
96
    /**
97
     * Registered date formats
98
     *
99
     * @access  protected
100
     * @var     array
101
     */
102
    var $dateFormats = array();
103
 
104
    /**
105
     * Registered time formats
106
     *
107
     * @access  protected
108
     * @var     array
109
     */
110
    var $timeFormats = array();
111
 
112
    /**
113
     * Registered datetime formats
114
     *
115
     * @access  protected
116
     * @var     array
117
     */
118
    var $dateTimeFormats = array();
119
 
120
    /**
121
     * Registered number formats
122
     *
123
     * @access  protected
124
     * @var     array
125
     */
126
    var $numberFormats = array();
127
 
128
    /**
129
     * Registered currency formats
130
     *
131
     * @access  protected
132
     * @var     array
133
     */
134
    var $currencyFormats = array();
135
 
136
    /**
137
     * Current time format
138
     *
139
     * @access  protected
140
     * @var     mixed
141
     */
142
    var $currentTimeFormat = null;
143
 
144
    /**
145
     * Current date format
146
     *
147
     * @access  protected
148
     * @var     mixed
149
     */
150
    var $currentDateFormat = null;
151
 
152
    /**
153
     * Current datetime format
154
     *
155
     * @access  protected
156
     * @var     mixed
157
     */
158
    var $currentDateTimeFormat = null;
159
 
160
    /**
161
     * Current number format
162
     *
163
     * @access  protected
164
     * @var     mixed
165
     */
166
    var $currentNumberFormat = null;
167
 
168
    /**
169
     * Current currency format
170
     *
171
     * @access  protected
172
     * @var     mixed
173
     */
174
    var $currentCurrencyFormat = null;
175
 
176
    /**
177
     * Custom formats
178
     *
179
     * @access  protected
180
     * @var     array
181
     */
182
    var $customFormats = array();
183
 
184
    /**
185
     * Locale Data Cache
186
     *
187
     * @access  protected
188
     * @var     array
189
     */
190
    var $cache = array();
191
 
192
    /**
193
     * Whether to reset the global locale after each call
194
     *
195
     * @access  protected
196
     * @var     bool
197
     */
198
    var $paranoid = false;
199
 
200
    /**
201
     * Store system locale for paranoid mode
202
     *
203
     * @access  protected
204
     * @var     string
205
     */
206
    var $usedLocale = '';
207
 
208
    /**
209
     * Constructor
210
     *
211
     * @access  public
212
     * @param   string  $locale
213
     */
214
    function I18Nv2_Locale($locale = null, $paranoid = false)
215
    {
216
        $locale or $locale = I18Nv2::lastLocale(0, 'locale');
217
        $this->setLocale($locale);
218
        $this->setParanoid($paranoid);
219
    }
220
 
221
    /**
222
     * Set locale
223
     *
224
     * This automatically calls I18Nv2_Locale::initialize()
225
     *
226
     * @access  public
227
     * @return  string  used system locale
228
     * @param   string  $locale
229
     * @param   bool    $force
230
     */
231
    function setLocale($locale, $force = false)
232
    {
233
        if (!$force && $this->initialized == $locale) {
234
            $last = I18Nv2::lastLocale(0, true);
235
            if (is_array($last)) {
236
                if (    $locale == $last['syslocale']   ||
237
                        $locale == $last['locale']      ||
238
                        $locale == $last['language']) {
239
                    return $last['syslocale'];
240
                }
241
            } elseif ($last == $locale) {
242
                return $last;
243
            }
244
        }
245
 
246
        return $this->initialize($locale);
247
    }
248
 
249
    /**
250
     * Initialize
251
     *
252
     * @access  public
253
     * @return  void
254
     */
255
    function initialize($locale)
256
    {
257
        $this->initialized = $locale;
258
        $this->usedLocale = I18Nv2::setLocale($locale);
259
 
260
        $jan = $mon = mktime(1,1,1,1,1,1990);
261
        $feb = $tue = mktime(1,1,1,2,6,1990);
262
        $mar = $wed = mktime(1,1,1,3,7,1990);
263
        $apr = $thu = mktime(1,1,1,4,5,1990);
264
        $may = $fri = mktime(1,1,1,5,4,1990);
265
        $jun = $sat = mktime(1,1,1,6,2,1990);
266
        $jul = $sun = mktime(1,1,1,7,1,1990);
267
        $aug = mktime(1,1,1,8,1,1990);
268
        $sep = mktime(1,1,1,9,1,1990);
269
        $oct = mktime(1,1,1,10,1,1990);
270
        $nov = mktime(1,1,1,11,1,1990);
271
        $dec = mktime(1,1,1,12,1,1990);
272
 
273
        if (!$this->loadCache($this->usedLocale)) {
274
            $this->days = array(
275
                strftime('%A', $sun),
276
                strftime('%A', $mon),
277
                strftime('%A', $tue),
278
                strftime('%A', $wed),
279
                strftime('%A', $thu),
280
                strftime('%A', $fri),
281
                strftime('%A', $sat),
282
            );
283
 
284
            $this->abbrDays = array(
285
                strftime('%a', $sun),
286
                strftime('%a', $mon),
287
                strftime('%a', $tue),
288
                strftime('%a', $wed),
289
                strftime('%a', $thu),
290
                strftime('%a', $fri),
291
                strftime('%a', $sat),
292
            );
293
 
294
            $this->months = array(
295
                strftime('%B', $jan),
296
                strftime('%B', $feb),
297
                strftime('%B', $mar),
298
                strftime('%B', $apr),
299
                strftime('%B', $may),
300
                strftime('%B', $jun),
301
                strftime('%B', $jul),
302
                strftime('%B', $aug),
303
                strftime('%B', $sep),
304
                strftime('%B', $oct),
305
                strftime('%B', $nov),
306
                strftime('%B', $dec),
307
            );
308
 
309
            $this->abbrMonths = array(
310
                strftime('%b', $jan),
311
                strftime('%b', $feb),
312
                strftime('%b', $mar),
313
                strftime('%b', $apr),
314
                strftime('%b', $may),
315
                strftime('%b', $jun),
316
                strftime('%b', $jul),
317
                strftime('%b', $aug),
318
                strftime('%b', $sep),
319
                strftime('%b', $oct),
320
                strftime('%b', $nov),
321
                strftime('%b', $dec),
322
            );
323
 
324
            $info = I18Nv2::getInfo();
325
 
326
            /*
327
             * The currency symbol is old shit on Win2k, though.
328
             * Some get extended/overwritten with other local conventions.
329
             */
330
            $this->currencyFormats = array(
331
                I18Nv2_CURRENCY_LOCAL => array(
332
                    $info['currency_symbol'],
333
                    $info['int_frac_digits'],
334
                    $info['mon_decimal_point'],
335
                    $info['mon_thousands_sep'],
336
                    $info['negative_sign'],
337
                    $info['positive_sign'],
338
                    $info['n_cs_precedes'],
339
                    $info['p_cs_precedes'],
340
                    $info['n_sep_by_space'],
341
                    $info['p_sep_by_space'],
342
                    $info['n_sign_posn'],
343
                    $info['p_sign_posn'],
344
                ),
345
                I18Nv2_CURRENCY_INTERNATIONAL => array(
346
                    $info['int_curr_symbol'],
347
                    $info['int_frac_digits'],
348
                    $info['mon_decimal_point'],
349
                    $info['mon_thousands_sep'],
350
                    $info['negative_sign'],
351
                    $info['positive_sign'],
352
                    $info['n_cs_precedes'],
353
                    $info['p_cs_precedes'],
354
                    true,
355
                    true,
356
                    $info['n_sign_posn'],
357
                    $info['p_sign_posn'],
358
                ),
359
            );
360
 
361
            $this->numberFormats = array(
362
                I18Nv2_NUMBER_FLOAT => array(
363
                    $info['frac_digits'],
364
                    $info['decimal_point'],
365
                    $info['thousands_sep']
366
                ),
367
                I18Nv2_NUMBER_INTEGER => array(
368
                    '0',
369
                    $info['decimal_point'],
370
                    $info['thousands_sep']
371
                ),
372
 
373
            );
374
 
375
            $this->loadExtension();
376
 
377
            if (!count($this->dateTimeFormats)) {
378
                $this->dateTimeFormats = array(
379
                    I18Nv2_DATETIME_SHORT   =>
380
                        $this->dateFormats[I18Nv2_DATETIME_SHORT]
381
                        . ', ' .
382
                        $this->timeFormats[I18Nv2_DATETIME_SHORT],
383
                    I18Nv2_DATETIME_MEDIUM   =>
384
                        $this->dateFormats[I18Nv2_DATETIME_MEDIUM]
385
                        . ', ' .
386
                        $this->timeFormats[I18Nv2_DATETIME_MEDIUM],
387
                    I18Nv2_DATETIME_DEFAULT   =>
388
                        $this->dateFormats[I18Nv2_DATETIME_DEFAULT]
389
                        . ', ' .
390
                        $this->timeFormats[I18Nv2_DATETIME_DEFAULT],
391
                    I18Nv2_DATETIME_LONG   =>
392
                        $this->dateFormats[I18Nv2_DATETIME_LONG]
393
                        . ', ' .
394
                        $this->timeFormats[I18Nv2_DATETIME_LONG],
395
                    I18Nv2_DATETIME_FULL   =>
396
                        $this->dateFormats[I18Nv2_DATETIME_FULL]
397
                        . ', ' .
398
                        $this->timeFormats[I18Nv2_DATETIME_FULL],
399
                );
400
            }
401
            $this->updateCache($this->usedLocale);
402
        }
403
 
404
        $this->setDefaults();
405
 
406
        if ($this->paranoid) {
407
            setlocale(LC_ALL, 'C');
408
        }
409
 
410
        return $this->usedLocale;
411
    }
412
 
413
    /**
414
     * Update Cache
415
     *
416
     * @access  protected
417
     * @return  void
418
     * @param   string  $locale
419
     */
420
    function updateCache($locale)
421
    {
422
        if (!isset($this->cache[$locale])) {
423
            $cache = get_object_vars($this);
424
            $cvars = preg_grep(
425
                '/^(init|current|custom|cache)/',
426
                array_keys($cache),
427
                PREG_GREP_INVERT
428
            );
429
            foreach ($cvars as $var) {
430
                $this->cache[$locale][$var] = $cache[$var];
431
            }
432
        }
433
    }
434
 
435
    /**
436
     * Load Cache
437
     *
438
     * @access  protected
439
     * @return  bool
440
     * @param   string  $locale
441
     */
442
    function loadCache($locale)
443
    {
444
        if (!isset($this->cache[$locale])) {
445
            return false;
446
        }
447
        foreach ($this->cache[$locale] as $var => $value) {
448
            $this->$var = $value;
449
        }
450
        return true;
451
    }
452
 
453
    /**
454
     * Loads corresponding locale extension
455
     *
456
     * @access  public
457
     * @return  void
458
     */
459
    function loadExtension()
460
    {
461
        $locale = I18Nv2::lastLocale(0, true);
462
        if (isset($locale)) {
463
            $dir = dirname(__FILE__);
464
            foreach (array($locale['language'], $locale['locale']) as $lc) {
465
                if (is_file($dir . '/Locale/' . $lc . '.php')) {
466
                    include $dir . '/Locale/' . $lc . '.php';
467
                }
468
            }
469
        }
470
    }
471
 
472
    /**
473
     * Set defaults
474
     *
475
     * @access  public
476
     * @return  void
477
     */
478
    function setDefaults()
479
    {
480
        $this->currentTimeFormat        = $this->timeFormats[I18Nv2_DATETIME_DEFAULT];
481
        $this->currentDateFormat        = $this->dateFormats[I18Nv2_DATETIME_DEFAULT];
482
        $this->currentDateTimeFormat    = $this->dateTimeFormats[I18Nv2_DATETIME_DEFAULT];
483
        $this->currentNumberFormat      = $this->numberFormats[I18Nv2_NUMBER_FLOAT];
484
        $this->currentCurrencyFormat    = $this->currencyFormats[I18Nv2_CURRENCY_INTERNATIONAL];
485
    }
486
 
487
    /**
488
     * Set Paranoid Mode
489
     *
490
     * Whether to reset to the C-locale after every call.
491
     *
492
     * @access  public
493
     * @return  void
494
     * @param   bool    $paranoid Whether to enable paranoid mode.
495
     */
496
    function setParanoid($paranoid = false)
497
    {
498
        $this->paranoid = (bool) $paranoid;
499
        $paranoid and setLocale(LC_ALL, 'C');
500
    }
501
 
502
    /**
503
     * Set currency format
504
     *
505
     * @access  public
506
     * @return  mixed   Returns &true; on success or <classname>PEAR_Error</classname> on failure.
507
     * @param   int     $format     a I18Nv2_CURRENCY constant
508
     * @param   bool    $custom     whether to use a defined custom format
509
     */
510
    function setCurrencyFormat($format, $custom = false)
511
    {
512
        if ($custom) {
513
            if (!isset($this->customFormats[$format])) {
514
                return PEAR::raiseError('Custom currency format "'.$format.'" doesn\'t exist.');
515
            }
516
            $this->currentCurrencyFormat = $this->customFormats[$format];
517
        } else {
518
            if (!isset($this->currencyFormats[$format])) {
519
                return PEAR::raiseError('Currency format "'.$format.'" doesn\'t exist.');
520
            }
521
            $this->currentCurrencyFormat = $this->currencyFormats[$format];
522
        }
523
        return true;
524
    }
525
 
526
    /**
527
     * Set number format
528
     *
529
     * @access  public
530
     * @return  mixed   Returns &true; on success or <classname>PEAR_Error</classname> on failure.
531
     * @param   int     $format     a I18Nv2_NUMBER constant
532
     * @param   bool    $custom     whether to use a defined custom format
533
     */
534
    function setNumberFormat($format, $custom = false)
535
    {
536
        if ($custom) {
537
            if (!isset($this->customFormats[$format])) {
538
                return PEAR::raiseError('Custom number format "'.$format.'" doesn\'t exist.');
539
            }
540
            $this->currentNumberFormat = $this->customFormats[$format];
541
        } else {
542
            if (!isset($this->numberFormats[$format])) {
543
                return PEAR::raiseError('Number format "'.$format.'" doesn\'t exist.');
544
            }
545
            $this->currentNumberFormat = $this->numberFormats[$format];
546
        }
547
        return true;
548
    }
549
 
550
    /**
551
     * Set date format
552
     *
553
     * @access  public
554
     * @return  mixed   Returns &true; on success or <classname>PEAR_Error</classname> on failure.
555
     * @param   int     $format     a I18Nv2_DATETIME constant
556
     * @param   bool    $custom     whether to use a defined custom format
557
     */
558
    function setDateFormat($format, $custom = false)
559
    {
560
        if ($custom) {
561
            if (!isset($this->customFormats[$format])) {
562
                return PEAR::raiseError('Custom date fromat "'.$format.'" doesn\'t exist.');
563
            }
564
            $this->currentDateFormat = $this->customFormats[$format];
565
        } else {
566
            if (!isset($this->dateFormats[$format])) {
567
                return PEAR::raiseError('Date format "'.$format.'" doesn\'t exist.');
568
            }
569
            $this->currentDateFormat = $this->dateFormats[$format];
570
        }
571
        return true;
572
    }
573
 
574
    /**
575
     * Set time format
576
     *
577
     * @access  public
578
     * @return  mixed
579
     * @param   int     $format     a I18Nv2_DATETIME constant
580
     * @param   bool    $custom     whether to use a defined custom format
581
     */
582
    function setTimeFormat($format, $custom = false)
583
    {
584
        if ($custom) {
585
            if (!isset($this->customFormats[$format])) {
586
                return PEAR::raiseError('Custom time format "'.$format.'" doesn\'t exist.');
587
            }
588
            $this->currentTimeFormat = $this->customFormats[$format];
589
        } else {
590
            if (!isset($this->timeFormats[$format])) {
591
                return PEAR::raiseError('Time format "'.$format.'" doesn\'t exist.');
592
            }
593
            $this->currentTimeFormat = $this->timeFormats[$format];
594
        }
595
        return true;
596
    }
597
 
598
    /**
599
     * Set datetime format
600
     *
601
     * @access  public
602
     * @return  mixed
603
     * @param   int     $format     a I18Nv2_DATETIME constant
604
     * @param   bool    $custom     whether to use a defined custom format
605
     */
606
    function setDateTimeFormat($format, $custom = false)
607
    {
608
        if ($custom) {
609
            if (!isset($this->customFormats[$format])) {
610
                return PEAR::raiseError('Custom datetime format "'.$format.'" doesn\'t exist.');
611
            }
612
            $this->currentDateTimeFormat = $this->customFormats[$format];
613
        } else {
614
            if (!isset($this->dateTimeFormats[$format])) {
615
                return PEAR::raiseError('Datetime format "'.$format.'" doesn\'t exist.');
616
            }
617
            $this->currentDateTimeFormat = $this->dateTimeFormats[$format];
618
        }
619
        return true;
620
    }
621
 
622
    /**
623
     * Set custom format
624
     *
625
     * If <var>$format</var> is omitted, the custom format for <var>$type</var>
626
     * will be dsicarded - if both vars are omitted all custom formats will
627
     * be discarded.
628
     *
629
     * @access  public
630
     * @return  void
631
     * @param   mixed   $type
632
     * @param   mixed   $format
633
     */
634
    function setCustomFormat($type = null, $format = null)
635
    {
636
        if (!isset($format)) {
637
            if (!isset($type)) {
638
                $this->customFormats = array();
639
            } else {
640
                unset($this->customFormats[$type]);
641
            }
642
        } else {
643
            $this->customFormats[$type] = $format;
644
        }
645
    }
646
 
647
    /**
648
     * Format currency
649
     *
650
     * @access  public
651
     * @return  string
652
     * @param   numeric $value
653
     * @param   int     $overrideFormat
654
     * @param   string  $overrideSymbol
655
     */
656
    function formatCurrency($value, $overrideFormat = null, $overrideSymbol = null)
657
    {
658
        @list(
659
            $symbol,
660
            $digits,
661
            $decpoint,
662
            $thseparator,
663
            $sign['-'],
664
            $sign['+'],
665
            $precedes['-'],
666
            $precedes['+'],
667
            $separate['-'],
668
            $separate['+'],
669
            $position['-'],
670
            $position['+']
671
        ) = isset($overrideFormat) ?
672
            $this->currencyFormats[$overrideFormat] :
673
            $this->currentCurrencyFormat;
674
 
675
        if (isset($overrideSymbol)) {
676
            $symbol = $overrideSymbol;
677
        }
678
 
679
        // number_format the absolute value
680
        $amount = number_format(abs($value), $digits, $decpoint, $thseparator);
681
 
682
        $S = $value < 0 ? '-' : '+';
683
 
684
        // check posittion of the positive/negative sign(s)
685
        switch ($position[$S])
686
        {
687
            case 0: $amount  = '('. $amount .')';   break;
688
            case 1: $amount  = $sign[$S] . $amount; break;
689
            case 2: $amount .= $sign[$S];           break;
690
            case 3: $symbol  = $sign[$S] . $symbol; break;
691
            case 4: $symbol .= $sign[$S];           break;
692
        }
693
 
694
        // currency symbol precedes amount
695
        if ($precedes[$S]) {
696
            $amount = $symbol . ($separate[$S] ? ' ':'') . $amount;
697
        }
698
        // currency symbol succedes amount
699
        else {
700
            $amount .= ($separate[$S] ? ' ':'') . $symbol;
701
        }
702
 
703
        return $amount;
704
    }
705
 
706
    /**
707
     * Format a number
708
     *
709
     * @access  public
710
     * @return  string
711
     * @param   numeric $value
712
     * @param   int     $overrideFormat
713
     */
714
    function formatNumber($value, $overrideFormat = null)
715
    {
716
        list($dig, $dec, $sep) = isset($overrideFormat) ?
717
            $this->numberFormats[$overrideFormat] :
718
            $this->currentNumberFormat;
719
        return number_format($value, $dig, $dec, $sep);
720
    }
721
 
722
    /**
723
     * Format a date
724
     *
725
     * @access  public
726
     * @return  string
727
     * @param   int     $timestamp
728
     * @param   int     $overrideFormat
729
     */
730
    function formatDate($timestamp = null, $overrideFormat = null)
731
    {
732
        $format = isset($overrideFormat) ?
733
            $this->dateFormats[$overrideFormat] : $this->currentDateFormat;
734
        $this->paranoid and setLocale(LC_ALL, $this->usedLocale);
735
        $date = strftime($format, isset($timestamp) ? $timestamp : time());
736
        $this->paranoid and setLocale(LC_ALL, 'C');
737
        return $date;
738
    }
739
 
740
    /**
741
     * Format a time
742
     *
743
     * @access  public
744
     * @return  string
745
     * @param   int     $timestamp
746
     * @param   int     $overrideFormat
747
     */
748
    function formatTime($timestamp = null, $overrideFormat = null)
749
    {
750
        $format = isset($overrideFormat) ?
751
            $this->timeFormats[$overrideFormat] : $this->currentTimeFormat;
752
        $this->paranoid and setLocale(LC_ALL, $this->usedLocale);
753
        $time = strftime($format, isset($timestamp) ? $timestamp : time());
754
        $this->paranoid and setLocale(LC_ALL, 'C');
755
        return $time;
756
    }
757
 
758
    /**
759
     * Format a datetime
760
     *
761
     * @access  public
762
     * @return  string
763
     * @param   int     $timestamp
764
     * @param   int     $overrideFormat
765
     */
766
    function formatDateTime($timestamp = null, $overrideFormat = null)
767
    {
768
        $format = isset($overrideFormat) ?
769
            $this->dateTimeFormats[$overrideFormat] :
770
            $this->currentDateTimeFormat;
771
        $this->paranoid and setLocale(LC_ALL, $this->usedLocale);
772
        $date = strftime($format, isset($timestamp) ? $timestamp : time());
773
        $this->paranoid and setLocale(LC_ALL, 'C');
774
        return $date;
775
    }
776
 
777
    /**
778
     * Locale time
779
     *
780
     * @access  public
781
     * @return  string
782
     * @param   int     $timestamp
783
     */
784
    function time($timestamp = null)
785
    {
786
        $this->paranoid and setLocale(LC_ALL, $this->usedLocale);
787
        $time = strftime('%X', isset($timestamp) ? $timestamp : time());
788
        $this->paranoid and setLocale(LC_ALL, 'C');
789
        return $time;
790
    }
791
 
792
    /**
793
     * Locale date
794
     *
795
     * @access  public
796
     * @return  string
797
     * @param   int     $timestamp
798
     */
799
    function date($timestamp = null)
800
    {
801
        $this->paranoid and setLocale(LC_ALL, $this->usedLocale);
802
        $date = strftime('%x', isset($timestamp) ? $timestamp : time());
803
        $this->paranoid and setLocale(LC_ALL, 'C');
804
        return $date;
805
    }
806
 
807
    /**
808
     * Day name
809
     *
810
     * @access  public
811
     * @return  mixed   Returns &type.string; name of weekday on success or
812
     *                  <classname>PEAR_Error</classname> on failure.
813
     * @param   int     $weekday    numerical representation of weekday
814
     *                              (0 = Sunday, 1 = Monday, ...)
815
     * @param   bool    $short  whether to return the abbreviation
816
     */
817
    function dayName($weekday, $short = false)
818
    {
819
        if ($short) {
820
            if (!isset($this->abbrDays[$weekday])) {
821
                return PEAR::raiseError('Weekday "'.$weekday.'" is out of range.');
822
            }
823
            return $this->abbrDays[$weekday];
824
        } else {
825
            if (!isset($this->days[$weekday])) {
826
                return PEAR::raiseError('Weekday "'.$weekday.'" is out of range.');
827
            }
828
            return $this->days[$weekday];
829
        }
830
    }
831
 
832
    /**
833
     * Month name
834
     *
835
     * @access  public
836
     * @return  mixed   Returns &type.string; name of month on success or
837
     *                  <classname>PEAR_Error</classname> on failure.
838
     * @param   int     $month  numerical representation of month
839
     *                          (0 = January, 1 = February, ...)
840
     * @param   bool    $short  whether to return the abbreviation
841
     */
842
    function monthName($month, $short = false)
843
    {
844
        if ($short) {
845
            if (!isset($this->abbrMonths[$month])) {
846
                return PEAR::raiseError('Month "'.$month.'" is out of range.');
847
            }
848
            return $this->abbrMonths[$month];
849
        } else {
850
            if (!isset($this->months[$month])) {
851
                return PEAR::raiseError('Month "'.$month.'" is out of range.');
852
            }
853
            return $this->months[$month];
854
        }
855
    }
856
}
857
?>