···11+<?php
22+33+declare(strict_types=1);
44+55+use PHPUnit\Framework\TestCase;
66+use PHPUnit\Framework\Attributes\TestDox;
77+88+/**
99+ * ATTENTION: We use function `from()` for backwards compatibility, not `add()`
1010+ */
1111+class GigasecondTest extends TestCase
1212+{
1313+ public static function setUpBeforeClass(): void
1414+ {
1515+ require_once 'Gigasecond.php';
1616+ }
1717+1818+ /** uuid: 92fbe71c-ea52-4fac-bd77-be38023cacf7 */
1919+ #[TestDox('Date only specification of time')]
2020+ public function testDateOnlySpecificationOfTime(): void
2121+ {
2222+ $UTC = new DateTimeZone('UTC');
2323+ $input = new DateTimeImmutable('2011-04-25', $UTC);
2424+2525+ $actual = from($input);
2626+2727+ $this->assertInstanceOf(DateTimeImmutable::class, $actual);
2828+ $this->assertSame(
2929+ '2043-01-01 01:46:40',
3030+ $actual->format('Y-m-d H:i:s'),
3131+ );
3232+ }
3333+3434+ /** uuid: 6d86dd16-6f7a-47be-9e58-bb9fb2ae1433 */
3535+ #[TestDox('Second test for date only specification of time')]
3636+ public function testSecondTestForDateOnlySpecificationOfTime(): void
3737+ {
3838+ $UTC = new DateTimeZone('UTC');
3939+ $input = new DateTimeImmutable('1977-06-13', $UTC);
4040+4141+ $actual = from($input);
4242+4343+ $this->assertInstanceOf(DateTimeImmutable::class, $actual);
4444+ $this->assertSame(
4545+ '2009-02-19 01:46:40',
4646+ $actual->format('Y-m-d H:i:s'),
4747+ );
4848+ }
4949+5050+ /** uuid: 77eb8502-2bca-4d92-89d9-7b39ace28dd5 */
5151+ #[TestDox('Third test for date only specification of time')]
5252+ public function testThirdTestForDateOnlySpecificationOfTime(): void
5353+ {
5454+ $UTC = new DateTimeZone('UTC');
5555+ $input = new DateTimeImmutable('1959-07-19', $UTC);
5656+5757+ $actual = from($input);
5858+5959+ $this->assertInstanceOf(DateTimeImmutable::class, $actual);
6060+ $this->assertSame(
6161+ '1991-03-27 01:46:40',
6262+ $actual->format('Y-m-d H:i:s'),
6363+ );
6464+ }
6565+6666+ /** uuid: c9d89a7d-06f8-4e28-a305-64f1b2abc693 */
6767+ #[TestDox('Full time specified')]
6868+ public function testFullTimeSpecified(): void
6969+ {
7070+ $UTC = new DateTimeZone('UTC');
7171+ $input = new DateTimeImmutable('2015-01-24 22:00:00', $UTC);
7272+7373+ $actual = from($input);
7474+7575+ $this->assertInstanceOf(DateTimeImmutable::class, $actual);
7676+ $this->assertSame(
7777+ '2046-10-02 23:46:40',
7878+ $actual->format('Y-m-d H:i:s'),
7979+ );
8080+ }
8181+8282+ /** uuid: 09d4e30e-728a-4b52-9005-be44a58d9eba */
8383+ #[TestDox('Full time with day roll-over')]
8484+ public function testFullTimeWithDayRollOver(): void
8585+ {
8686+ $UTC = new DateTimeZone('UTC');
8787+ $input = new DateTimeImmutable('2015-01-24 23:59:59', $UTC);
8888+8989+ $actual = from($input);
9090+9191+ $this->assertInstanceOf(DateTimeImmutable::class, $actual);
9292+ $this->assertSame(
9393+ '2046-10-03 01:46:39',
9494+ $actual->format('Y-m-d H:i:s'),
9595+ );
9696+ }
9797+}
+59
php/gigasecond/README.md
···11+# Gigasecond
22+33+Welcome to Gigasecond on Exercism's PHP Track.
44+If you need help running the tests or submitting your code, check out `HELP.md`.
55+66+## Introduction
77+88+The way we measure time is kind of messy.
99+We have 60 seconds in a minute, and 60 minutes in an hour.
1010+This comes from ancient Babylon, where they used 60 as the basis for their number system.
1111+We have 24 hours in a day, 7 days in a week, and how many days in a month?
1212+Well, for days in a month it depends not only on which month it is, but also on what type of calendar is used in the country you live in.
1313+1414+What if, instead, we only use seconds to express time intervals?
1515+Then we can use metric system prefixes for writing large numbers of seconds in more easily comprehensible quantities.
1616+1717+- A food recipe might explain that you need to let the brownies cook in the oven for two kiloseconds (that's two thousand seconds).
1818+- Perhaps you and your family would travel to somewhere exotic for two megaseconds (that's two million seconds).
1919+- And if you and your spouse were married for _a thousand million_ seconds, you would celebrate your one gigasecond anniversary.
2020+2121+~~~~exercism/note
2222+If we ever colonize Mars or some other planet, measuring time is going to get even messier.
2323+If someone says "year" do they mean a year on Earth or a year on Mars?
2424+2525+The idea for this exercise came from the science fiction novel ["A Deepness in the Sky"][vinge-novel] by author Vernor Vinge.
2626+In it the author uses the metric system as the basis for time measurements.
2727+2828+[vinge-novel]: https://www.tor.com/2017/08/03/science-fiction-with-something-for-everyone-a-deepness-in-the-sky-by-vernor-vinge/
2929+~~~~
3030+3131+## Instructions
3232+3333+Your task is to determine the date and time one gigasecond after a certain date.
3434+3535+A gigasecond is one thousand million seconds.
3636+That is a one with nine zeros after it.
3737+3838+If you were born on _January 24th, 2015 at 22:00 (10:00:00pm)_, then you would be a gigasecond old on _October 2nd, 2046 at 23:46:40 (11:46:40pm)_.
3939+4040+## Source
4141+4242+### Contributed to by
4343+4444+- @arueckauer
4545+- @dkinzer
4646+- @Dog
4747+- @kunicmarko20
4848+- @kytrinyx
4949+- @lafent
5050+- @MatheusNaldi
5151+- @petemcfarlane
5252+- @peteraba
5353+- @TFarla
5454+- @tstirrat15
5555+- @zembrowski
5656+5757+### Based on
5858+5959+Chapter 9 in Chris Pine's online Learn to Program tutorial. - https://pine.fm/LearnToProgram/chap_09.html