| 1 | <?php |
| 2 | /************************************************************* |
| 3 | # 076 License |
| 4 | |
| 5 | Copyright (c) テクニカル諏訪子 |
| 6 | |
| 7 | Permission is hereby granted to any person obtaining a copy of the software |
| 8 | Little Beast (the "Software") to use, modify, merge, copy, publish, distribute, |
| 9 | sublicense, and/or sell copies of the Software, subject to the following conditions: |
| 10 | |
| 11 | 1. **Origin Attribution**: |
| 12 | - You must not misrepresent the origin of the Software; you must not claim |
| 13 | you created the original Software. |
| 14 | - If the Software is used in a product, you must either: |
| 15 | a. Provide clear attribution in the product's documentation, user interface, |
| 16 | or other visible areas, **OR** |
| 17 | b. Pay the original developers a fee they specify in writing. |
| 18 | 2. **Usage Restriction**: |
| 19 | - The Software, or any derivative works, dependencies, or libraries |
| 20 | incorporating it, must not be used for censorship or to suppress freedom of |
| 21 | speech, expression, or creativity. Prohibited uses include, but are not |
| 22 | limited to: |
| 23 | - Censorship of so-called "hate speech", visuals, non-mainstream opinions, |
| 24 | ideas, or objective reality. |
| 25 | - Tools or systems designed to restrict access to information or |
| 26 | artistic works. |
| 27 | 3. **Notice Preservation**: |
| 28 | - This license and the above copyright notice must remain intact in all copies |
| 29 | of the source code. |
| 30 | |
| 31 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
| 32 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A |
| 33 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 34 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 35 | CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE |
| 36 | OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 37 | */ |
| 38 | namespace Std\Lib\Git; |
| 39 | |
| 40 | /** |
| 41 | * 作者・コミッター(「名前 <メール> 時刻 +0900」) |
| 42 | */ |
| 43 | final class Person { |
| 44 | /** |
| 45 | * @param string $name 名前 |
| 46 | * @param string $email メールアドレス |
| 47 | * @param int $time UNIX時刻 |
| 48 | * @param string $tz 時差(「+0900」) |
| 49 | */ |
| 50 | public function __construct(public string $name, public string $email, public int $time, public string $tz = '+0000') {} |
| 51 | |
| 52 | public static function parse(string $s): self { |
| 53 | if (preg_match('/^(.*?) ?<([^>]*)> (-?\d+) ([+-]\d{4})$/s', $s, $m)) return new self($m[1], $m[2], (int)$m[3], $m[4]); |
| 54 | if (preg_match('/^(.*?) ?<([^>]*)>/s', $s, $m)) return new self($m[1], $m[2], 0, '+0000'); |
| 55 | return new self($s, '', 0, '+0000'); |
| 56 | } |
| 57 | |
| 58 | /** 今の時刻で(時差はPHPの時間帯) */ |
| 59 | public static function now(string $name, string $email): self { |
| 60 | $t = new \DateTimeImmutable(); |
| 61 | return new self($name, $email, $t->getTimestamp(), $t->format('O')); |
| 62 | } |
| 63 | |
| 64 | public function __toString(): string { |
| 65 | return "{$this->name} <{$this->email}> {$this->time} {$this->tz}"; |
| 66 | } |
| 67 | |
| 68 | /** 時差を付けた日時 */ |
| 69 | public function date(): \DateTimeImmutable { |
| 70 | return (new \DateTimeImmutable('@'.$this->time))->setTimezone(new \DateTimeZone($this->tz)); |
| 71 | } |
| 72 | } |