-
Notifications
You must be signed in to change notification settings - Fork 1
/
Date.php
4955 lines (4364 loc) · 193 KB
/
Date.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Date
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Date.php 24880 2012-06-12 20:35:18Z matthew $
*/
/**
* Include needed Date classes
*/
require_once 'Zend/Date/DateObject.php';
require_once 'Zend/Locale.php';
require_once 'Zend/Locale/Format.php';
require_once 'Zend/Locale/Math.php';
/**
* @category Zend
* @package Zend_Date
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Date extends Zend_Date_DateObject
{
private $_locale = null;
// Fractional second variables
private $_fractional = 0;
private $_precision = 3;
private static $_options = array(
'format_type' => 'iso', // format for date strings 'iso' or 'php'
'fix_dst' => true, // fix dst on summer/winter time change
'extend_month' => false, // false - addMonth like SQL, true like excel
'cache' => null, // cache to set
'timesync' => null // timesync server to set
);
// Class wide Date Constants
const DAY = 'dd';
const DAY_SHORT = 'd';
const DAY_SUFFIX = 'SS';
const DAY_OF_YEAR = 'D';
const WEEKDAY = 'EEEE';
const WEEKDAY_SHORT = 'EEE';
const WEEKDAY_NARROW = 'E';
const WEEKDAY_NAME = 'EE';
const WEEKDAY_8601 = 'eee';
const WEEKDAY_DIGIT = 'e';
const WEEK = 'ww';
const MONTH = 'MM';
const MONTH_SHORT = 'M';
const MONTH_DAYS = 'ddd';
const MONTH_NAME = 'MMMM';
const MONTH_NAME_SHORT = 'MMM';
const MONTH_NAME_NARROW = 'MMMMM';
const YEAR = 'y';
const YEAR_SHORT = 'yy';
const YEAR_8601 = 'Y';
const YEAR_SHORT_8601 = 'YY';
const LEAPYEAR = 'l';
const MERIDIEM = 'a';
const SWATCH = 'B';
const HOUR = 'HH';
const HOUR_SHORT = 'H';
const HOUR_AM = 'hh';
const HOUR_SHORT_AM = 'h';
const MINUTE = 'mm';
const MINUTE_SHORT = 'm';
const SECOND = 'ss';
const SECOND_SHORT = 's';
const MILLISECOND = 'S';
const TIMEZONE_NAME = 'zzzz';
const DAYLIGHT = 'I';
const GMT_DIFF = 'Z';
const GMT_DIFF_SEP = 'ZZZZ';
const TIMEZONE = 'z';
const TIMEZONE_SECS = 'X';
const ISO_8601 = 'c';
const RFC_2822 = 'r';
const TIMESTAMP = 'U';
const ERA = 'G';
const ERA_NAME = 'GGGG';
const ERA_NARROW = 'GGGGG';
const DATES = 'F';
const DATE_FULL = 'FFFFF';
const DATE_LONG = 'FFFF';
const DATE_MEDIUM = 'FFF';
const DATE_SHORT = 'FF';
const TIMES = 'WW';
const TIME_FULL = 'TTTTT';
const TIME_LONG = 'TTTT';
const TIME_MEDIUM = 'TTT';
const TIME_SHORT = 'TT';
const DATETIME = 'K';
const DATETIME_FULL = 'KKKKK';
const DATETIME_LONG = 'KKKK';
const DATETIME_MEDIUM = 'KKK';
const DATETIME_SHORT = 'KK';
const ATOM = 'OOO';
const COOKIE = 'CCC';
const RFC_822 = 'R';
const RFC_850 = 'RR';
const RFC_1036 = 'RRR';
const RFC_1123 = 'RRRR';
const RFC_3339 = 'RRRRR';
const RSS = 'SSS';
const W3C = 'WWW';
/**
* Generates the standard date object, could be a unix timestamp, localized date,
* string, integer, array and so on. Also parts of dates or time are supported
* Always set the default timezone: http://php.net/date_default_timezone_set
* For example, in your bootstrap: date_default_timezone_set('America/Los_Angeles');
* For detailed instructions please look in the docu.
*
* @param string|integer|Zend_Date|array $date OPTIONAL Date value or value of date part to set
* ,depending on $part. If null the actual time is set
* @param string $part OPTIONAL Defines the input format of $date
* @param string|Zend_Locale $locale OPTIONAL Locale for parsing input
* @return Zend_Date
* @throws Zend_Date_Exception
*/
public function __construct($date = null, $part = null, $locale = null)
{
if (is_object($date) and !($date instanceof Zend_TimeSync_Protocol) and
!($date instanceof Zend_Date)) {
if ($locale instanceof Zend_Locale) {
$locale = $date;
$date = null;
$part = null;
} else {
$date = (string) $date;
}
}
if (($date !== null) and !is_array($date) and !($date instanceof Zend_TimeSync_Protocol) and
!($date instanceof Zend_Date) and !defined($date) and Zend_Locale::isLocale($date, true, false)) {
$locale = $date;
$date = null;
$part = null;
} else if (($part !== null) and !defined($part) and Zend_Locale::isLocale($part, true, false)) {
$locale = $part;
$part = null;
}
$this->setLocale($locale);
if (is_string($date) && ($part === null) && (strlen($date) <= 5)) {
$part = $date;
$date = null;
}
if ($date === null) {
if ($part === null) {
$date = time();
} else if ($part !== self::TIMESTAMP) {
$date = self::now($locale);
$date = $date->get($part);
}
}
if ($date instanceof Zend_TimeSync_Protocol) {
$date = $date->getInfo();
$date = $this->_getTime($date['offset']);
$part = null;
} else if (parent::$_defaultOffset != 0) {
$date = $this->_getTime(parent::$_defaultOffset);
}
// set the timezone and offset for $this
$zone = @date_default_timezone_get();
$this->setTimezone($zone);
// try to get timezone from date-string
if (!is_int($date)) {
$zone = $this->getTimezoneFromString($date);
$this->setTimezone($zone);
}
// set datepart
if (($part !== null && $part !== self::TIMESTAMP) or (!is_numeric($date))) {
// switch off dst handling for value setting
$this->setUnixTimestamp($this->getGmtOffset());
$this->set($date, $part, $this->_locale);
// DST fix
if (is_array($date) === true) {
if (!isset($date['hour'])) {
$date['hour'] = 0;
}
$hour = $this->toString('H', 'iso', true);
$hour = $date['hour'] - $hour;
switch ($hour) {
case 1 :
case -23 :
$this->addTimestamp(3600);
break;
case -1 :
case 23 :
$this->subTimestamp(3600);
break;
case 2 :
case -22 :
$this->addTimestamp(7200);
break;
case -2 :
case 22 :
$this->subTimestamp(7200);
break;
}
}
} else {
$this->setUnixTimestamp($date);
}
}
/**
* Sets class wide options, if no option was given, the actual set options will be returned
*
* @param array $options Options to set
* @throws Zend_Date_Exception
* @return Options array if no option was given
*/
public static function setOptions(array $options = array())
{
if (empty($options)) {
return self::$_options;
}
foreach ($options as $name => $value) {
$name = strtolower($name);
if (array_key_exists($name, self::$_options)) {
switch($name) {
case 'format_type' :
if ((strtolower($value) != 'php') && (strtolower($value) != 'iso')) {
require_once 'Zend/Date/Exception.php';
throw new Zend_Date_Exception("Unknown format type ($value) for dates, only 'iso' and 'php' supported", 0, null, $value);
}
break;
case 'fix_dst' :
if (!is_bool($value)) {
require_once 'Zend/Date/Exception.php';
throw new Zend_Date_Exception("'fix_dst' has to be boolean", 0, null, $value);
}
break;
case 'extend_month' :
if (!is_bool($value)) {
require_once 'Zend/Date/Exception.php';
throw new Zend_Date_Exception("'extend_month' has to be boolean", 0, null, $value);
}
break;
case 'cache' :
if ($value === null) {
parent::$_cache = null;
} else {
if (!$value instanceof Zend_Cache_Core) {
require_once 'Zend/Date/Exception.php';
throw new Zend_Date_Exception("Instance of Zend_Cache expected");
}
parent::$_cache = $value;
parent::$_cacheTags = Zend_Date_DateObject::_getTagSupportForCache();
Zend_Locale_Data::setCache($value);
}
break;
case 'timesync' :
if ($value === null) {
parent::$_defaultOffset = 0;
} else {
if (!$value instanceof Zend_TimeSync_Protocol) {
require_once 'Zend/Date/Exception.php';
throw new Zend_Date_Exception("Instance of Zend_TimeSync expected");
}
$date = $value->getInfo();
parent::$_defaultOffset = $date['offset'];
}
break;
}
self::$_options[$name] = $value;
}
else {
require_once 'Zend/Date/Exception.php';
throw new Zend_Date_Exception("Unknown option: $name = $value");
}
}
}
/**
* Returns this object's internal UNIX timestamp (equivalent to Zend_Date::TIMESTAMP).
* If the timestamp is too large for integers, then the return value will be a string.
* This function does not return the timestamp as an object.
* Use clone() or copyPart() instead.
*
* @return integer|string UNIX timestamp
*/
public function getTimestamp()
{
return $this->getUnixTimestamp();
}
/**
* Returns the calculated timestamp
* HINT: timestamps are always GMT
*
* @param string $calc Type of calculation to make
* @param string|integer|array|Zend_Date $stamp Timestamp to calculate, when null the actual timestamp is calculated
* @return Zend_Date|integer
* @throws Zend_Date_Exception
*/
private function _timestamp($calc, $stamp)
{
if ($stamp instanceof Zend_Date) {
// extract timestamp from object
$stamp = $stamp->getTimestamp();
}
if (is_array($stamp)) {
if (isset($stamp['timestamp']) === true) {
$stamp = $stamp['timestamp'];
} else {
require_once 'Zend/Date/Exception.php';
throw new Zend_Date_Exception('no timestamp given in array');
}
}
if ($calc === 'set') {
$return = $this->setUnixTimestamp($stamp);
} else {
$return = $this->_calcdetail($calc, $stamp, self::TIMESTAMP, null);
}
if ($calc != 'cmp') {
return $this;
}
return $return;
}
/**
* Sets a new timestamp
*
* @param integer|string|array|Zend_Date $timestamp Timestamp to set
* @return Zend_Date Provides fluid interface
* @throws Zend_Date_Exception
*/
public function setTimestamp($timestamp)
{
return $this->_timestamp('set', $timestamp);
}
/**
* Adds a timestamp
*
* @param integer|string|array|Zend_Date $timestamp Timestamp to add
* @return Zend_Date Provides fluid interface
* @throws Zend_Date_Exception
*/
public function addTimestamp($timestamp)
{
return $this->_timestamp('add', $timestamp);
}
/**
* Subtracts a timestamp
*
* @param integer|string|array|Zend_Date $timestamp Timestamp to sub
* @return Zend_Date Provides fluid interface
* @throws Zend_Date_Exception
*/
public function subTimestamp($timestamp)
{
return $this->_timestamp('sub', $timestamp);
}
/**
* Compares two timestamps, returning the difference as integer
*
* @param integer|string|array|Zend_Date $timestamp Timestamp to compare
* @return integer 0 = equal, 1 = later, -1 = earlier
* @throws Zend_Date_Exception
*/
public function compareTimestamp($timestamp)
{
return $this->_timestamp('cmp', $timestamp);
}
/**
* Returns a string representation of the object
* Supported format tokens are:
* G - era, y - year, Y - ISO year, M - month, w - week of year, D - day of year, d - day of month
* E - day of week, e - number of weekday (1-7), h - hour 1-12, H - hour 0-23, m - minute, s - second
* A - milliseconds of day, z - timezone, Z - timezone offset, S - fractional second, a - period of day
*
* Additionally format tokens but non ISO conform are:
* SS - day suffix, eee - php number of weekday(0-6), ddd - number of days per month
* l - Leap year, B - swatch internet time, I - daylight saving time, X - timezone offset in seconds
* r - RFC2822 format, U - unix timestamp
*
* Not supported ISO tokens are
* u - extended year, Q - quarter, q - quarter, L - stand alone month, W - week of month
* F - day of week of month, g - modified julian, c - stand alone weekday, k - hour 0-11, K - hour 1-24
* v - wall zone
*
* @param string $format OPTIONAL Rule for formatting output. If null the default date format is used
* @param string $type OPTIONAL Type for the format string which overrides the standard setting
* @param string|Zend_Locale $locale OPTIONAL Locale for parsing input
* @return string
*/
public function toString($format = null, $type = null, $locale = null)
{
if (is_object($format)) {
if ($format instanceof Zend_Locale) {
$locale = $format;
$format = null;
} else {
$format = (string) $format;
}
}
if (is_object($type)) {
if ($type instanceof Zend_Locale) {
$locale = $type;
$type = null;
} else {
$type = (string) $type;
}
}
if (($format !== null) && !defined($format)
&& ($format != 'ee') && ($format != 'ss') && ($format != 'GG') && ($format != 'MM') && ($format != 'EE') && ($format != 'TT')
&& Zend_Locale::isLocale($format, null, false)) {
$locale = $format;
$format = null;
}
if (($type !== null) and ($type != 'php') and ($type != 'iso') and
Zend_Locale::isLocale($type, null, false)) {
$locale = $type;
$type = null;
}
if ($locale === null) {
$locale = $this->getLocale();
}
if ($format === null) {
$format = Zend_Locale_Format::getDateFormat($locale) . ' ' . Zend_Locale_Format::getTimeFormat($locale);
} else if (((self::$_options['format_type'] == 'php') && ($type === null)) or ($type == 'php')) {
$format = Zend_Locale_Format::convertPhpToIsoFormat($format);
}
return $this->date($this->_toToken($format, $locale), $this->getUnixTimestamp(), false);
}
/**
* Returns a string representation of the date which is equal with the timestamp
*
* @return string
*/
public function __toString()
{
return $this->toString(null, $this->_locale);
}
/**
* Returns a integer representation of the object
* But returns false when the given part is no value f.e. Month-Name
*
* @param string|integer|Zend_Date $part OPTIONAL Defines the date or datepart to return as integer
* @return integer|false
*/
public function toValue($part = null)
{
$result = $this->get($part);
if (is_numeric($result)) {
return intval("$result");
} else {
return false;
}
}
/**
* Returns an array representation of the object
*
* @return array
*/
public function toArray()
{
return array('day' => $this->toString(self::DAY_SHORT, 'iso'),
'month' => $this->toString(self::MONTH_SHORT, 'iso'),
'year' => $this->toString(self::YEAR, 'iso'),
'hour' => $this->toString(self::HOUR_SHORT, 'iso'),
'minute' => $this->toString(self::MINUTE_SHORT, 'iso'),
'second' => $this->toString(self::SECOND_SHORT, 'iso'),
'timezone' => $this->toString(self::TIMEZONE, 'iso'),
'timestamp' => $this->toString(self::TIMESTAMP, 'iso'),
'weekday' => $this->toString(self::WEEKDAY_8601, 'iso'),
'dayofyear' => $this->toString(self::DAY_OF_YEAR, 'iso'),
'week' => $this->toString(self::WEEK, 'iso'),
'gmtsecs' => $this->toString(self::TIMEZONE_SECS, 'iso'));
}
/**
* Returns a representation of a date or datepart
* This could be for example a localized monthname, the time without date,
* the era or only the fractional seconds. There are about 50 different supported date parts.
* For a complete list of supported datepart values look into the docu
*
* @param string $part OPTIONAL Part of the date to return, if null the timestamp is returned
* @param string|Zend_Locale $locale OPTIONAL Locale for parsing input
* @return string date or datepart
*/
public function get($part = null, $locale = null)
{
if ($locale === null) {
$locale = $this->getLocale();
}
if (($part !== null) && !defined($part)
&& ($part != 'ee') && ($part != 'ss') && ($part != 'GG') && ($part != 'MM') && ($part != 'EE') && ($part != 'TT')
&& Zend_Locale::isLocale($part, null, false)) {
$locale = $part;
$part = null;
}
if ($part === null) {
$part = self::TIMESTAMP;
} else if (self::$_options['format_type'] == 'php') {
$part = Zend_Locale_Format::convertPhpToIsoFormat($part);
}
return $this->date($this->_toToken($part, $locale), $this->getUnixTimestamp(), false);
}
/**
* Internal method to apply tokens
*
* @param string $part
* @param string $locale
* @return string
*/
private function _toToken($part, $locale) {
// get format tokens
$comment = false;
$format = '';
$orig = '';
for ($i = 0; isset($part[$i]); ++$i) {
if ($part[$i] == "'") {
$comment = $comment ? false : true;
if (isset($part[$i+1]) && ($part[$i+1] == "'")) {
$comment = $comment ? false : true;
$format .= "\\'";
++$i;
}
$orig = '';
continue;
}
if ($comment) {
$format .= '\\' . $part[$i];
$orig = '';
} else {
$orig .= $part[$i];
if (!isset($part[$i+1]) || (isset($orig[0]) && ($orig[0] != $part[$i+1]))) {
$format .= $this->_parseIsoToDate($orig, $locale);
$orig = '';
}
}
}
return $format;
}
/**
* Internal parsing method
*
* @param string $token
* @param string $locale
* @return string
*/
private function _parseIsoToDate($token, $locale) {
switch($token) {
case self::DAY :
return 'd';
break;
case self::WEEKDAY_SHORT :
$weekday = strtolower($this->date('D', $this->getUnixTimestamp(), false));
$day = Zend_Locale_Data::getContent($locale, 'day', array('gregorian', 'format', 'wide', $weekday));
return $this->_toComment(iconv_substr($day, 0, 3, 'UTF-8'));
break;
case self::DAY_SHORT :
return 'j';
break;
case self::WEEKDAY :
$weekday = strtolower($this->date('D', $this->getUnixTimestamp(), false));
return $this->_toComment(Zend_Locale_Data::getContent($locale, 'day', array('gregorian', 'format', 'wide', $weekday)));
break;
case self::WEEKDAY_8601 :
return 'N';
break;
case 'ee' :
return $this->_toComment(str_pad($this->date('N', $this->getUnixTimestamp(), false), 2, '0', STR_PAD_LEFT));
break;
case self::DAY_SUFFIX :
return 'S';
break;
case self::WEEKDAY_DIGIT :
return 'w';
break;
case self::DAY_OF_YEAR :
return 'z';
break;
case 'DDD' :
return $this->_toComment(str_pad($this->date('z', $this->getUnixTimestamp(), false), 3, '0', STR_PAD_LEFT));
break;
case 'DD' :
return $this->_toComment(str_pad($this->date('z', $this->getUnixTimestamp(), false), 2, '0', STR_PAD_LEFT));
break;
case self::WEEKDAY_NARROW :
case 'EEEEE' :
$weekday = strtolower($this->date('D', $this->getUnixTimestamp(), false));
$day = Zend_Locale_Data::getContent($locale, 'day', array('gregorian', 'format', 'abbreviated', $weekday));
return $this->_toComment(iconv_substr($day, 0, 1, 'UTF-8'));
break;
case self::WEEKDAY_NAME :
$weekday = strtolower($this->date('D', $this->getUnixTimestamp(), false));
return $this->_toComment(Zend_Locale_Data::getContent($locale, 'day', array('gregorian', 'format', 'abbreviated', $weekday)));
break;
case 'w' :
$week = $this->date('W', $this->getUnixTimestamp(), false);
return $this->_toComment(($week[0] == '0') ? $week[1] : $week);
break;
case self::WEEK :
return 'W';
break;
case self::MONTH_NAME :
$month = $this->date('n', $this->getUnixTimestamp(), false);
return $this->_toComment(Zend_Locale_Data::getContent($locale, 'month', array('gregorian', 'format', 'wide', $month)));
break;
case self::MONTH :
return 'm';
break;
case self::MONTH_NAME_SHORT :
$month = $this->date('n', $this->getUnixTimestamp(), false);
return $this->_toComment(Zend_Locale_Data::getContent($locale, 'month', array('gregorian', 'format', 'abbreviated', $month)));
break;
case self::MONTH_SHORT :
return 'n';
break;
case self::MONTH_DAYS :
return 't';
break;
case self::MONTH_NAME_NARROW :
$month = $this->date('n', $this->getUnixTimestamp(), false);
$mon = Zend_Locale_Data::getContent($locale, 'month', array('gregorian', 'format', 'abbreviated', $month));
return $this->_toComment(iconv_substr($mon, 0, 1, 'UTF-8'));
break;
case self::LEAPYEAR :
return 'L';
break;
case self::YEAR_8601 :
return 'o';
break;
case self::YEAR :
return 'Y';
break;
case self::YEAR_SHORT :
return 'y';
break;
case self::YEAR_SHORT_8601 :
return $this->_toComment(substr($this->date('o', $this->getUnixTimestamp(), false), -2, 2));
break;
case self::MERIDIEM :
$am = $this->date('a', $this->getUnixTimestamp(), false);
if ($am == 'am') {
return $this->_toComment(Zend_Locale_Data::getContent($locale, 'am'));
}
return $this->_toComment(Zend_Locale_Data::getContent($locale, 'pm'));
break;
case self::SWATCH :
return 'B';
break;
case self::HOUR_SHORT_AM :
return 'g';
break;
case self::HOUR_SHORT :
return 'G';
break;
case self::HOUR_AM :
return 'h';
break;
case self::HOUR :
return 'H';
break;
case self::MINUTE :
return $this->_toComment(str_pad($this->date('i', $this->getUnixTimestamp(), false), 2, '0', STR_PAD_LEFT));
break;
case self::SECOND :
return $this->_toComment(str_pad($this->date('s', $this->getUnixTimestamp(), false), 2, '0', STR_PAD_LEFT));
break;
case self::MINUTE_SHORT :
return 'i';
break;
case self::SECOND_SHORT :
return 's';
break;
case self::MILLISECOND :
return $this->_toComment($this->getMilliSecond());
break;
case self::TIMEZONE_NAME :
case 'vvvv' :
return 'e';
break;
case self::DAYLIGHT :
return 'I';
break;
case self::GMT_DIFF :
case 'ZZ' :
case 'ZZZ' :
return 'O';
break;
case self::GMT_DIFF_SEP :
return 'P';
break;
case self::TIMEZONE :
case 'v' :
case 'zz' :
case 'zzz' :
return 'T';
break;
case self::TIMEZONE_SECS :
return 'Z';
break;
case self::ISO_8601 :
return 'c';
break;
case self::RFC_2822 :
return 'r';
break;
case self::TIMESTAMP :
return 'U';
break;
case self::ERA :
case 'GG' :
case 'GGG' :
$year = $this->date('Y', $this->getUnixTimestamp(), false);
if ($year < 0) {
return $this->_toComment(Zend_Locale_Data::getContent($locale, 'era', array('gregorian', 'Abbr', '0')));
}
return $this->_toComment(Zend_Locale_Data::getContent($locale, 'era', array('gregorian', 'Abbr', '1')));
break;
case self::ERA_NARROW :
$year = $this->date('Y', $this->getUnixTimestamp(), false);
if ($year < 0) {
return $this->_toComment(iconv_substr(Zend_Locale_Data::getContent($locale, 'era', array('gregorian', 'Abbr', '0')), 0, 1, 'UTF-8')) . '.';
}
return $this->_toComment(iconv_substr(Zend_Locale_Data::getContent($locale, 'era', array('gregorian', 'Abbr', '1')), 0, 1, 'UTF-8')) . '.';
break;
case self::ERA_NAME :
$year = $this->date('Y', $this->getUnixTimestamp(), false);
if ($year < 0) {
return $this->_toComment(Zend_Locale_Data::getContent($locale, 'era', array('gregorian', 'Names', '0')));
}
return $this->_toComment(Zend_Locale_Data::getContent($locale, 'era', array('gregorian', 'Names', '1')));
break;
case self::DATES :
return $this->_toToken(Zend_Locale_Format::getDateFormat($locale), $locale);
break;
case self::DATE_FULL :
return $this->_toToken(Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'full')), $locale);
break;
case self::DATE_LONG :
return $this->_toToken(Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'long')), $locale);
break;
case self::DATE_MEDIUM :
return $this->_toToken(Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'medium')), $locale);
break;
case self::DATE_SHORT :
return $this->_toToken(Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'short')), $locale);
break;
case self::TIMES :
return $this->_toToken(Zend_Locale_Format::getTimeFormat($locale), $locale);
break;
case self::TIME_FULL :
return $this->_toToken(Zend_Locale_Data::getContent($locale, 'time', 'full'), $locale);
break;
case self::TIME_LONG :
return $this->_toToken(Zend_Locale_Data::getContent($locale, 'time', 'long'), $locale);
break;
case self::TIME_MEDIUM :
return $this->_toToken(Zend_Locale_Data::getContent($locale, 'time', 'medium'), $locale);
break;
case self::TIME_SHORT :
return $this->_toToken(Zend_Locale_Data::getContent($locale, 'time', 'short'), $locale);
break;
case self::DATETIME :
return $this->_toToken(Zend_Locale_Format::getDateTimeFormat($locale), $locale);
break;
case self::DATETIME_FULL :
return $this->_toToken(Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'full')), $locale);
break;
case self::DATETIME_LONG :
return $this->_toToken(Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'long')), $locale);
break;
case self::DATETIME_MEDIUM :
return $this->_toToken(Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'medium')), $locale);
break;
case self::DATETIME_SHORT :
return $this->_toToken(Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'short')), $locale);
break;
case self::ATOM :
return 'Y\-m\-d\TH\:i\:sP';
break;
case self::COOKIE :
return 'l\, d\-M\-y H\:i\:s e';
break;
case self::RFC_822 :
return 'D\, d M y H\:i\:s O';
break;
case self::RFC_850 :
return 'l\, d\-M\-y H\:i\:s e';
break;
case self::RFC_1036 :
return 'D\, d M y H\:i\:s O';
break;
case self::RFC_1123 :
return 'D\, d M Y H\:i\:s O';
break;
case self::RFC_3339 :
return 'Y\-m\-d\TH\:i\:sP';
break;
case self::RSS :
return 'D\, d M Y H\:i\:s O';
break;
case self::W3C :
return 'Y\-m\-d\TH\:i\:sP';
break;
}
if ($token == '') {
return '';
}
switch ($token[0]) {
case 'y' :
if ((strlen($token) == 4) && (abs($this->getUnixTimestamp()) <= 0x7FFFFFFF)) {
return 'Y';
}
$length = iconv_strlen($token, 'UTF-8');
return $this->_toComment(str_pad($this->date('Y', $this->getUnixTimestamp(), false), $length, '0', STR_PAD_LEFT));
break;
case 'Y' :
if ((strlen($token) == 4) && (abs($this->getUnixTimestamp()) <= 0x7FFFFFFF)) {
return 'o';
}
$length = iconv_strlen($token, 'UTF-8');
return $this->_toComment(str_pad($this->date('o', $this->getUnixTimestamp(), false), $length, '0', STR_PAD_LEFT));
break;
case 'A' :
$length = iconv_strlen($token, 'UTF-8');
$result = substr($this->getMilliSecond(), 0, 3);
$result += $this->date('s', $this->getUnixTimestamp(), false) * 1000;
$result += $this->date('i', $this->getUnixTimestamp(), false) * 60000;
$result += $this->date('H', $this->getUnixTimestamp(), false) * 3600000;
return $this->_toComment(str_pad($result, $length, '0', STR_PAD_LEFT));
break;
}
return $this->_toComment($token);
}
/**
* Private function to make a comment of a token
*
* @param string $token
* @return string
*/
private function _toComment($token)
{
$token = str_split($token);
$result = '';
foreach ($token as $tok) {
$result .= '\\' . $tok;
}
return $result;
}
/**
* Return digit from standard names (english)
* Faster implementation than locale aware searching
*
* @param string $name
* @return integer Number of this month
* @throws Zend_Date_Exception
*/
private function _getDigitFromName($name)
{
switch($name) {
case "Jan":
return 1;
case "Feb":
return 2;