  |
1 | 1 | | <?php |
| |
2 | 2 | | /* |
  |
3 | | - | $Id: datetime.php 153 2005-08-04 12:57:59Z hpdl $ |
| |
| 3 | + | $Id: datetime.php 386 2006-01-12 11:36:39Z hpdl $ |
|
4 | 4 | | |
| |
5 | 5 | | osCommerce, Open Source E-Commerce Solutions |
| |
6 | 6 | | http://www.oscommerce.com |
| |
7 | 7 | | |
  |
8 | | - | Copyright (c) 2004 osCommerce |
| |
| 8 | + | Copyright (c) 2006 osCommerce |
|
9 | 9 | | |
| |
10 | 10 | | Released under the GNU General Public License |
| |
11 | 11 | | */ |
| |
12 | 12 | | |
| |
13 | 13 | | class osC_DateTime { |
  |
14 | | - | var $date = '', |
| |
15 | | - | $month = '', |
| |
16 | | - | $year = '', |
| |
17 | | - | $hour = '', |
| |
18 | | - | $minute = '', |
| |
19 | | - | $second = '', |
| |
20 | | - | $long_date_format = '', |
| |
21 | | - | $short_date_format = '', |
| |
22 | | - | $long_date = '', |
| |
23 | | - | $short_date = ''; |
| |
| 14 | + | function getNow() { |
| |
| 15 | + | return date('Y-m-d H:i:s'); |
| |
| 16 | + | } |
|
24 | 17 | | |
  |
25 | | - | function osC_DateTime($raw_date = '', $long_date_format = '', $short_date_format = '') { |
| |
26 | | - | if (tep_not_null($long_date_format)) { |
| |
27 | | - | $this->long_date_format = $long_date_format; |
| |
28 | | - | } else { |
| |
29 | | - | $this->long_date_format = DATE_FORMAT_LONG; |
| |
30 | | - | } |
| |
| 18 | + | function getShort($date = '') { |
| |
| 19 | + | global $osC_Language; |
|
31 | 20 | | |
  |
32 | | - | if (tep_not_null($short_date_format)) { |
| |
33 | | - | $this->short_date_format = $short_date_format; |
| |
34 | | - | } else { |
| |
35 | | - | $this->short_date_format = DATE_FORMAT; |
| |
| 21 | + | if (empty($date)) { |
| |
| 22 | + | $date = osC_DateTime::getNow(); |
|
36 | 23 | | } |
| |
37 | 24 | | |
  |
38 | | - | if (tep_not_null($raw_date)) { |
| |
39 | | - | $this->format($raw_date); |
| |
| 25 | + | $year = substr($date, 0, 4); |
| |
| 26 | + | $month = (int)substr($date, 5, 2); |
| |
| 27 | + | $day = (int)substr($date, 8, 2); |
| |
| 28 | + | $hour = (int)substr($date, 11, 2); |
| |
| 29 | + | $minute = (int)substr($date, 14, 2); |
| |
| 30 | + | $second = (int)substr($date, 17, 2); |
| |
| 31 | + | |
| |
| 32 | + | if (@date('Y', mktime($hour, $minute, $second, $month, $day, $year)) == $year) { |
| |
| 33 | + | return strftime($osC_Language->getDateFormatShort(), mktime($hour, $minute, $second, $month, $day, $year)); |
|
40 | 34 | | } else { |
  |
41 | | - | $this->setCurrentDate(); |
| |
| 35 | + | return ereg_replace('2037', $year, strftime($osC_Language->getDateFormatShort(), mktime($hour, $minute, $second, $month, $day, 2037))); |
|
42 | 36 | | } |
| |
43 | 37 | | } |
| |
44 | 38 | | |
  |
45 | | - | function setCurrentDate() { |
| |
46 | | - | $this->date = date('d'); |
| |
47 | | - | $this->month = date('m'); |
| |
48 | | - | $this->year = date('Y'); |
| |
| 39 | + | function getLong($date = '') { |
| |
| 40 | + | global $osC_Language; |
|
49 | 41 | | |
  |
50 | | - | $this->hour = date('H'); |
| |
51 | | - | $this->minute = date('i'); |
| |
52 | | - | $this->second = date('s'); |
| |
53 | | - | } |
| |
54 | | - | |
| |
55 | | - | function format($raw_date) { |
| |
56 | | - | if (empty($raw_date) || ($raw_date == '0000-00-00 00:00:00')) { |
| |
57 | | - | return false; |
| |
| 42 | + | if (empty($date)) { |
| |
| 43 | + | $date = osC_DateTime::getNow(); |
|
58 | 44 | | } |
| |
59 | 45 | | |
  |
60 | | - | $this->year = (int)substr($raw_date, 0, 4); |
| |
61 | | - | $this->month = (int)substr($raw_date, 5, 2); |
| |
62 | | - | $this->day = (int)substr($raw_date, 8, 2); |
| |
63 | | - | $this->hour = (int)substr($raw_date, 11, 2); |
| |
64 | | - | $this->minute = (int)substr($raw_date, 14, 2); |
| |
65 | | - | $this->second = (int)substr($raw_date, 17, 2); |
| |
| 46 | + | $year = substr($date, 0, 4); |
| |
| 47 | + | $month = (int)substr($date, 5, 2); |
| |
| 48 | + | $day = (int)substr($date, 8, 2); |
| |
| 49 | + | $hour = (int)substr($date, 11, 2); |
| |
| 50 | + | $minute = (int)substr($date, 14, 2); |
| |
| 51 | + | $second = (int)substr($date, 17, 2); |
|
66 | 52 | | |
  |
67 | | - | $this->long_date = strftime($this->long_date_format, mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year)); |
| |
68 | | - | |
| |
69 | | - | if (@date('Y', mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year)) == $this->year) { |
| |
70 | | - | $this->short_date = date($this->short_date_format, mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year)); |
| |
| 53 | + | if (@date('Y', mktime($hour, $minute, $second, $month, $day, $year)) == $year) { |
| |
| 54 | + | return strftime($osC_Language->getDateFormatLong(), mktime($hour, $minute, $second, $month, $day, $year)); |
|
71 | 55 | | } else { |
  |
72 | | - | $this->short_date = ereg_replace('2037$', $this->year, date($this->short_date_format, mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, 2037))); |
| |
| 56 | + | return ereg_replace('2037', $year, strftime($osC_Language->getDateFormatLong(), mktime($hour, $minute, $second, $month, $day, 2037))); |
  |
73 | 57 | | } |
| |
74 | 58 | | } |
| |
75 | 59 | | |