Bladeren bron

première version

Frederic G. Marand 19 jaren geleden
bovenliggende
commit
0ffc13fae1
1 gewijzigde bestanden met toevoegingen van 118 en 0 verwijderingen
  1. 118 0
      u_date_code.php

+ 118 - 0
u_date_code.php

@@ -0,0 +1,118 @@
+<?php
+/**
+ * Handle standard OSInet date code strings, uppercase
+ * format: [y]ymdd
+ * 4-characters until 2009-12-31, 5 afterwards
+ *
+ * $Id: u_date_code.php,v 1.1 2006-11-26 15:48:35 marand Exp $
+ */
+
+require_once('misc.php');          // needed for "iComparable" interface
+require_once('boxed_scalars.php'); // needed to sign-compare ints
+
+class osinet_date_code implements iComparable
+  {
+  private $f_value;
+
+  /**
+   * Implements iComparable restrictively, only comparing to other osinet_date_code
+   * objects, not to any other class implementing iComparable
+   *
+   */
+  public function cmp(iComparable $other)
+    {
+    if (!($other instanceof osinet_date_code))
+      throw new Exception('osinet_date_code only compares to other osinet_date_code objects');
+
+    $ar_d1 = $this->to_mkdate();
+    $d1 = new boxed_int($ar_d1['mday']);
+    $m1 = new boxed_int($ar_d1['mon']) ;
+    $y1 = new boxed_int($ar_d1['year']);
+
+    $ar_d2 = $other->to_mkdate();
+    $d2 = new boxed_int($ar_d2['mday']);
+    $m2 = new boxed_int($ar_d2['mon']) ;
+    $y2 = new boxed_int($ar_d2['year']);
+
+    $ret = $y1->cmp($y2);
+    if ($ret)
+      return $ret;
+    else // same year
+      {
+      $ret = $m1->cmp($m2);
+      if ($ret)
+        return $ret;
+      else // same year and month
+        {
+        $ret = $d1->cmp($d2);
+        return $ret;
+        }
+      }
+    }
+
+  /**
+   * Generate an mkdate()-like array for a date code
+   *
+   * @param string $date_code
+   * @return array ['mday', 'mon', 'year']
+   */
+  public function to_mkdate()
+    {
+    $date_code = strtoupper($this->f_value);
+    $matches = array();
+    preg_match('/^([0-9]*)([A-Z])([0-9]?.*$)/', $date_code, $matches);
+    if (count($matches) <> 4)
+      {
+      throw new Exception("Incorrect date code $date_code");
+      }
+    $ret = array(
+      'mday' => $matches[3],
+      'mon'  => ord($matches[2]) - ord('@'),
+      'year' => 2000 + $matches[1],
+      );
+    return $ret;
+    }
+
+  public function __construct($time = null)
+    {
+    if (!$time)
+      $time = time();
+    $date = getdate();
+    $day   = $date['mday'];
+    $month = $date['mon'];
+    $year  = $date['year'] % 100;
+
+    $month = chr(ord('@') + $month);
+
+    return sprintf('%d%s%02d', $year, $month, $day);
+    }
+
+  private function set_value($date_code)
+    {
+    $date_code = strtoupper($date_code);
+    $matches = array();
+    preg_match('/^([0-9]*)([A-Z])([0-9]?.*$)/', $date_code, $matches);
+    if (count($matches) <> 4)
+      {
+      throw new Exception("Incorrect date code $date_code");
+      }
+    else
+      $this->f_value = $date_code;
+    }
+
+  protected function __get($nm)
+    {
+    if ($nm <> 'value')
+      throw new Exception("$nm: undefined property for " . get_class($this));
+
+    return $this->f_value;
+    }
+
+  private function __set($nm, $val)
+    {
+    if ($nm <> 'value')
+      throw new Exception("$nm: undefined property for " . get_class($this));
+
+    $this->set_value($val);
+    }
+  }

PANIC: session(release): write data/sessions/d/3/d37969ea3b7467f2: no space left on device

PANIC

session(release): write data/sessions/d/3/d37969ea3b7467f2: no space left on device
/my/cache/.heroku/go/go-path/pkg/mod/github.com/go-macaron/session@v1.0.3/session.go:204 (0xb13e07)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/context.go:80 (0x967b75)
/my/cache/.heroku/go/go-path/pkg/mod/github.com/go-macaron/inject@v0.0.0-20200308113650-138e5925c53b/inject.go:157 (0x9512ee)
/my/cache/.heroku/go/go-path/pkg/mod/github.com/go-macaron/inject@v0.0.0-20200308113650-138e5925c53b/inject.go:135 (0x951205)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/context.go:124 (0x967cc4)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/context.go:114 (0x967bf6)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/recovery.go:161 (0x15baec4)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/logger.go:40 (0x96b257)
/my/cache/.heroku/go/go-path/pkg/mod/github.com/go-macaron/inject@v0.0.0-20200308113650-138e5925c53b/inject.go:157 (0x9512ee)
/my/cache/.heroku/go/go-path/pkg/mod/github.com/go-macaron/inject@v0.0.0-20200308113650-138e5925c53b/inject.go:135 (0x951205)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/context.go:124 (0x967cc4)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/router.go:187 (0x972959)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/router.go:304 (0x973a01)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/macaron.go:218 (0x96c572)
/my/cache/.heroku/go/go1.26.3/go/src/net/http/server.go:3311 (0x85a5cd)
/my/cache/.heroku/go/go1.26.3/go/src/net/http/server.go:2073 (0x837f6f)
/my/cache/.heroku/go/go1.26.3/go/src/runtime/asm_amd64.s:1771 (0x493380)