Subversion Repositories oidplus

Rev

Blame | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * Copyright (C) 2008 Patrik Fimml
  5.  * Copyright (c) 2023 Daniel Marschall
  6.  *
  7.  * This file is part of glip.
  8.  *
  9.  * glip is free software: you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation, either version 2 of the License, or
  12.  * (at your option) any later version.
  13.  
  14.  * glip is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with glip.  If not, see <http://www.gnu.org/licenses/>.
  21.  */
  22.  
  23. namespace ViaThinkSoft\Glip;
  24.  
  25. class GitCommitStamp
  26. {
  27.         public $name;
  28.         public $email;
  29.         public $time;
  30.         public $offset;
  31.  
  32.         public function unserialize($data) {
  33.                 $res = preg_match('/^(.+?)\s+<(.+?)>\s+(\d+)\s+([+-]\d{4})$/', $data, $m);
  34.                 assert($res);
  35.                 $this->name = $m[1];
  36.                 $this->email = $m[2];
  37.                 $this->time = intval($m[3]);
  38.                 $off = intval($m[4]);
  39.                 $this->offset = ($off / 100) * 3600 + ($off % 100) * 60;
  40.         }
  41.  
  42.         public function serialize() {
  43.                 if ($this->offset % 60)
  44.                         throw new \Exception('cannot serialize sub-minute timezone offset');
  45.                 return sprintf('%s <%s> %d %+05d', $this->name, $this->email, $this->time, ($this->offset / 3600) * 100 + ($this->offset / 60) % 60);
  46.         }
  47. }
  48.