PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.15.2
Independent Analytics – WordPress Analytics Plugin v2.15.2
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / vendor / nesbot / carbon / src / Carbon / Traits / Timestamp.php
independent-analytics / vendor / nesbot / carbon / src / Carbon / Traits Last commit date
Boundaries.php 2 years ago Cast.php 2 years ago Comparison.php 1 year ago Converter.php 2 years ago Creator.php 2 years ago Date.php 1 month ago DeprecatedProperties.php 2 years ago Difference.php 2 years ago IntervalRounding.php 2 years ago IntervalStep.php 2 years ago Localization.php 1 month ago Macro.php 2 years ago MagicParameter.php 2 years ago Mixin.php 2 years ago Modifiers.php 2 years ago Mutability.php 2 years ago ObjectInitialisation.php 2 years ago Options.php 1 year ago Rounding.php 2 years ago Serialization.php 2 years ago Test.php 1 month ago Timestamp.php 1 month ago ToStringFormat.php 2 years ago Units.php 2 years ago Week.php 2 years ago
Timestamp.php
183 lines
1 <?php
2
3 /**
4 * This file is part of the Carbon package.
5 *
6 * (c) Brian Nesbitt <brian@nesbot.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11 namespace IAWPSCOPED\Carbon\Traits;
12
13 /**
14 * Trait Timestamp.
15 * @internal
16 */
17 trait Timestamp
18 {
19 /**
20 * Create a Carbon instance from a timestamp and set the timezone (use default one if not specified).
21 *
22 * Timestamp input can be given as int, float or a string containing one or more numbers.
23 *
24 * @param float|int|string $timestamp
25 * @param \DateTimeZone|string|null $tz
26 *
27 * @return static
28 */
29 #[\ReturnTypeWillChange]
30 public static function createFromTimestamp($timestamp, $tz = null)
31 {
32 return static::createFromTimestampUTC($timestamp)->setTimezone($tz);
33 }
34 /**
35 * Create a Carbon instance from an timestamp keeping the timezone to UTC.
36 *
37 * Timestamp input can be given as int, float or a string containing one or more numbers.
38 *
39 * @param float|int|string $timestamp
40 *
41 * @return static
42 */
43 public static function createFromTimestampUTC($timestamp)
44 {
45 [$integer, $decimal] = self::getIntegerAndDecimalParts($timestamp);
46 $delta = \floor($decimal / static::MICROSECONDS_PER_SECOND);
47 $integer += $delta;
48 $decimal -= $delta * static::MICROSECONDS_PER_SECOND;
49 $decimal = \str_pad((string) $decimal, 6, '0', \STR_PAD_LEFT);
50 return static::rawCreateFromFormat('U u', "{$integer} {$decimal}");
51 }
52 /**
53 * Create a Carbon instance from a timestamp in milliseconds.
54 *
55 * Timestamp input can be given as int, float or a string containing one or more numbers.
56 *
57 * @param float|int|string $timestamp
58 *
59 * @return static
60 */
61 public static function createFromTimestampMsUTC($timestamp)
62 {
63 [$milliseconds, $microseconds] = self::getIntegerAndDecimalParts($timestamp, 3);
64 $sign = $milliseconds < 0 || $milliseconds === 0.0 && $microseconds < 0 ? -1 : 1;
65 $milliseconds = \abs($milliseconds);
66 $microseconds = $sign * \abs($microseconds) + static::MICROSECONDS_PER_MILLISECOND * ($milliseconds % static::MILLISECONDS_PER_SECOND);
67 $seconds = $sign * \floor($milliseconds / static::MILLISECONDS_PER_SECOND);
68 $delta = \floor($microseconds / static::MICROSECONDS_PER_SECOND);
69 $seconds += $delta;
70 $microseconds -= $delta * static::MICROSECONDS_PER_SECOND;
71 $microseconds = \str_pad($microseconds, 6, '0', \STR_PAD_LEFT);
72 return static::rawCreateFromFormat('U u', "{$seconds} {$microseconds}");
73 }
74 /**
75 * Create a Carbon instance from a timestamp in milliseconds.
76 *
77 * Timestamp input can be given as int, float or a string containing one or more numbers.
78 *
79 * @param float|int|string $timestamp
80 * @param \DateTimeZone|string|null $tz
81 *
82 * @return static
83 */
84 public static function createFromTimestampMs($timestamp, $tz = null)
85 {
86 return static::createFromTimestampMsUTC($timestamp)->setTimezone($tz);
87 }
88 /**
89 * Set the instance's timestamp.
90 *
91 * Timestamp input can be given as int, float or a string containing one or more numbers.
92 *
93 * @param float|int|string $unixTimestamp
94 *
95 * @return static
96 */
97 public function timestamp($unixTimestamp)
98 {
99 return $this->setTimestamp($unixTimestamp);
100 }
101 /**
102 * Returns a timestamp rounded with the given precision (6 by default).
103 *
104 * @example getPreciseTimestamp() 1532087464437474 (microsecond maximum precision)
105 * @example getPreciseTimestamp(6) 1532087464437474
106 * @example getPreciseTimestamp(5) 153208746443747 (1/100000 second precision)
107 * @example getPreciseTimestamp(4) 15320874644375 (1/10000 second precision)
108 * @example getPreciseTimestamp(3) 1532087464437 (millisecond precision)
109 * @example getPreciseTimestamp(2) 153208746444 (1/100 second precision)
110 * @example getPreciseTimestamp(1) 15320874644 (1/10 second precision)
111 * @example getPreciseTimestamp(0) 1532087464 (second precision)
112 * @example getPreciseTimestamp(-1) 153208746 (10 second precision)
113 * @example getPreciseTimestamp(-2) 15320875 (100 second precision)
114 *
115 * @param int $precision
116 *
117 * @return float
118 */
119 public function getPreciseTimestamp($precision = 6)
120 {
121 return \round((float) $this->rawFormat('Uu') / \pow(10, 6 - $precision));
122 }
123 /**
124 * Returns the milliseconds timestamps used amongst other by Date javascript objects.
125 *
126 * @return float
127 */
128 public function valueOf()
129 {
130 return $this->getPreciseTimestamp(3);
131 }
132 /**
133 * Returns the timestamp with millisecond precision.
134 *
135 * @return int
136 */
137 public function getTimestampMs()
138 {
139 return (int) $this->getPreciseTimestamp(3);
140 }
141 /**
142 * @alias getTimestamp
143 *
144 * Returns the UNIX timestamp for the current date.
145 *
146 * @return int
147 */
148 public function unix()
149 {
150 return $this->getTimestamp();
151 }
152 /**
153 * Return an array with integer part digits and decimals digits split from one or more positive numbers
154 * (such as timestamps) as string with the given number of decimals (6 by default).
155 *
156 * By splitting integer and decimal, this method obtain a better precision than
157 * number_format when the input is a string.
158 *
159 * @param float|int|string $numbers one or more numbers
160 * @param int $decimals number of decimals precision (6 by default)
161 *
162 * @return array 0-index is integer part, 1-index is decimal part digits
163 */
164 private static function getIntegerAndDecimalParts($numbers, $decimals = 6)
165 {
166 if (\is_int($numbers) || \is_float($numbers)) {
167 $numbers = \number_format($numbers, $decimals, '.', '');
168 }
169 $sign = \str_starts_with($numbers, '-') ? -1 : 1;
170 $integer = 0;
171 $decimal = 0;
172 foreach (\preg_split('`[^\\d.]+`', $numbers) as $chunk) {
173 [$integerPart, $decimalPart] = \explode('.', "{$chunk}.");
174 $integer += (int) $integerPart;
175 $decimal += (float) "0.{$decimalPart}";
176 }
177 $overflow = \floor($decimal);
178 $integer += $overflow;
179 $decimal -= $overflow;
180 return [$sign * $integer, $decimal === 0.0 ? 0.0 : $sign * \round($decimal * \pow(10, $decimals))];
181 }
182 }
183