Page MenuHomeDevCentral

D4076.diff
No OneTemporary

D4076.diff

diff --git a/omnitools/src/DateTime/DateStamp.php b/omnitools/src/DateTime/DateStamp.php
--- a/omnitools/src/DateTime/DateStamp.php
+++ b/omnitools/src/DateTime/DateStamp.php
@@ -14,37 +14,37 @@
class DateStamp {
///
- /// Private members
+ /// Constructors
///
/**
- * @var int
+ * Build a date from specified year, month and day
*/
- private $year;
+ public function __construct (
+ public int $year,
+ public int $month,
+ public int $day,
+ ) {
+ }
/**
- * @var int
+ * Build a date from the specified UNIX time
+ *
+ * @param int $unixtime The unix time
+ * @return self
*/
- private $month;
+ public static function fromUnixTime (int $unixtime) : self {
+ $dateStamp = date('Y-m-d', $unixtime);
+ return self::parse($dateStamp);
+ }
/**
- * @var int
+ * Represent the current date
+ *
+ * @return static
*/
- private $day;
-
- ///
- /// Constructors
- ///
-
- public function __construct (int $year, int $month, int $day) {
- $this->year = $year;
- $this->month = $month;
- $this->day = $day;
- }
-
- public static function fromUnixTime (?int $unixtime = null) : self {
- $dateStamp = date('Y-m-d', $unixtime ?? time());
- return self::parse($dateStamp);
+ public static function now () : self {
+ return self::fromUnixTime(time());
}
/**
diff --git a/omnitools/tests/DateTime/DateStampTest.php b/omnitools/tests/DateTime/DateStampTest.php
--- a/omnitools/tests/DateTime/DateStampTest.php
+++ b/omnitools/tests/DateTime/DateStampTest.php
@@ -54,6 +54,13 @@
);
}
+ public function testNow () : void {
+ $expected = date('Y-m-d');
+
+ $now = DateStamp::now();
+ $this->assertEquals($expected, (string)$now);
+ }
+
public function testParse () : void {
$this->assertEquals(
$this->dateStamp,
diff --git a/omnitools/tests/Reflection/CodeClassTest.php b/omnitools/tests/Reflection/CodeClassTest.php
--- a/omnitools/tests/Reflection/CodeClassTest.php
+++ b/omnitools/tests/Reflection/CodeClassTest.php
@@ -71,7 +71,7 @@
$services = [
// Some objects (in different order than the constructor)
"request" => new Request(),
- "date" => DateStamp::fromUnixTime(), // another name than in class
+ "date" => DateStamp::now(), // another name than in class
"session" => new HashMap(),
// Scalar values

File Metadata

Mime Type
text/plain
Expires
Mon, Apr 20, 05:47 (17 h, 27 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3642617
Default Alt Text
D4076.diff (2 KB)

Event Timeline