|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * @copyright Copyright (c) 2022, Joas Schilling <coding@schilljs.com> |
| 7 | + * |
| 8 | + * @author Joas Schilling <coding@schilljs.com> |
| 9 | + * |
| 10 | + * @license AGPL-3.0 |
| 11 | + * |
| 12 | + * This code is free software: you can redistribute it and/or modify |
| 13 | + * it under the terms of the GNU Affero General Public License, version 3, |
| 14 | + * as published by the Free Software Foundation. |
| 15 | + * |
| 16 | + * This program is distributed in the hope that it will be useful, |
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | + * GNU Affero General Public License for more details. |
| 20 | + * |
| 21 | + * You should have received a copy of the GNU Affero General Public License, version 3, |
| 22 | + * along with this program. If not, see <http://www.gnu.org/licenses/> |
| 23 | + * |
| 24 | + */ |
| 25 | + |
| 26 | +namespace Test\AppFramework\Utility; |
| 27 | + |
| 28 | +use OC\AppFramework\Utility\TimeFactory; |
| 29 | + |
| 30 | +class TimeFactoryTest extends \Test\TestCase { |
| 31 | + protected TimeFactory $timeFactory; |
| 32 | + |
| 33 | + protected function setUp(): void { |
| 34 | + $this->timeFactory = new TimeFactory(); |
| 35 | + } |
| 36 | + |
| 37 | + public function testNow(): void { |
| 38 | + $now = $this->timeFactory->now(); |
| 39 | + self::assertSame('UTC', $now->getTimezone()->getName()); |
| 40 | + } |
| 41 | + |
| 42 | + public function testNowWithTimeZone(): void { |
| 43 | + $timezone = new \DateTimeZone('Europe/Berlin'); |
| 44 | + $withTimeZone = $this->timeFactory->withTimeZone($timezone); |
| 45 | + |
| 46 | + $now = $withTimeZone->now(); |
| 47 | + self::assertSame('Europe/Berlin', $now->getTimezone()->getName()); |
| 48 | + } |
| 49 | +} |
0 commit comments