Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F25975421
D4076.id10639.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D4076.id10639.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Mon, Apr 20, 09:24 (10 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3642617
Default Alt Text
D4076.id10639.diff (2 KB)
Attached To
Mode
D4076: Refactor DateStamp with constructor property promotion
Attached
Detach File
Event Timeline
Log In to Comment