Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 401 and 402] [Versions 401 and 403]

   1  <?php
   2  
   3  namespace PhpXmlRpc\Helper;
   4  
   5  class Date
   6  {
   7      /**
   8       * Given a timestamp, return the corresponding ISO8601 encoded string.
   9       *
  10       * Really, timezones ought to be supported but the XML-RPC spec says:
  11       *
  12       * "Don't assume a timezone. It should be specified by the server in its documentation what assumptions it makes
  13       *  about timezones."
  14       *
  15       * These routines always assume localtime unless $utc is set to 1, in which case UTC is assumed and an adjustment
  16       * for locale is made when encoding
  17       *
  18       * @param int $timet (timestamp)
  19       * @param int $utc (0 or 1)
  20       *
  21       * @return string
  22       */
  23      public static function iso8601Encode($timet, $utc = 0)
  24      {
  25          if (!$utc) {
  26              $t = date('Ymd\TH:i:s', $timet);
  27          } else {
  28              $t = gmdate('Ymd\TH:i:s', $timet);
  29          }
  30  
  31          return $t;
  32      }
  33  
  34      /**
  35       * Given an ISO8601 date string, return a timet in the localtime, or UTC.
  36       *
  37       * @param string $idate
  38       * @param int $utc either 0 or 1
  39       *
  40       * @return int (datetime)
  41       */
  42      public static function iso8601Decode($idate, $utc = 0)
  43      {
  44          $t = 0;
  45          if (preg_match('/([0-9]{4})([0-1][0-9])([0-3][0-9])T([0-2][0-9]):([0-5][0-9]):([0-5][0-9])/', $idate, $regs)) {
  46              if ($utc) {
  47                  $t = gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
  48              } else {
  49                  $t = mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
  50              }
  51          }
  52  
  53          return $t;
  54      }
  55  }