~ubuntu-branches/debian/experimental/php-nette/experimental

« back to all changes in this revision

Viewing changes to Nette-2.1.0RC/Nette/common/DateTime.php

  • Committer: Package Import Robot
  • Author(s): David Prévot
  • Date: 2013-11-30 08:47:54 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20131130084754-4udf1xsu9085tnfc
Tags: 2.1.0~rc-1
* New upstream branch
* Update copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/**
 
4
 * This file is part of the Nette Framework (http://nette.org)
 
5
 *
 
6
 * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
 
7
 *
 
8
 * For the full copyright and license information, please view
 
9
 * the file license.txt that was distributed with this source code.
 
10
 */
 
11
 
 
12
namespace Nette;
 
13
 
 
14
use Nette;
 
15
 
 
16
 
 
17
/**
 
18
 * DateTime.
 
19
 *
 
20
 * @author     David Grudl
 
21
 */
 
22
class DateTime extends \DateTime
 
23
{
 
24
        /** minute in seconds */
 
25
        const MINUTE = 60;
 
26
 
 
27
        /** hour in seconds */
 
28
        const HOUR = 3600;
 
29
 
 
30
        /** day in seconds */
 
31
        const DAY = 86400;
 
32
 
 
33
        /** week in seconds */
 
34
        const WEEK = 604800;
 
35
 
 
36
        /** average month in seconds */
 
37
        const MONTH = 2629800;
 
38
 
 
39
        /** average year in seconds */
 
40
        const YEAR = 31557600;
 
41
 
 
42
 
 
43
        /**
 
44
         * DateTime object factory.
 
45
         * @param  string|int|\DateTime
 
46
         * @return DateTime
 
47
         */
 
48
        public static function from($time)
 
49
        {
 
50
                if ($time instanceof \DateTime || $time instanceof \DateTimeInterface) {
 
51
                        return new static($time->format('Y-m-d H:i:s'), $time->getTimezone());
 
52
 
 
53
                } elseif (is_numeric($time)) {
 
54
                        if ($time <= self::YEAR) {
 
55
                                $time += time();
 
56
                        }
 
57
                        return new static(date('Y-m-d H:i:s', $time));
 
58
 
 
59
                } else { // textual or NULL
 
60
                        return new static($time);
 
61
                }
 
62
        }
 
63
 
 
64
 
 
65
        public function __toString()
 
66
        {
 
67
                return $this->format('Y-m-d H:i:s');
 
68
        }
 
69
 
 
70
 
 
71
        public function modifyClone($modify = '')
 
72
        {
 
73
                $dolly = clone $this;
 
74
                return $modify ? $dolly->modify($modify) : $dolly;
 
75
        }
 
76
 
 
77
}