Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

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

   1  <?php
   2  
   3  /**
   4   *  BENNU - PHP iCalendar library
   5   *  (c) 2005-2006 Ioannis Papaioannou (pj@moodle.org). All rights reserved.
   6   *
   7   *  Released under the LGPL.
   8   *
   9   *  See http://bennu.sourceforge.net/ for more information and downloads.
  10   *
  11   * @author Ioannis Papaioannou
  12   * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  13   */
  14  
  15  class Bennu {
  16      static function timestamp_to_datetime($t = NULL) {
  17          if($t === NULL) {
  18              $t = time();
  19          }
  20          return gmstrftime('%Y%m%dT%H%M%SZ', $t);
  21      }
  22  
  23      static function timestamp_to_date($t = NULL) {
  24          if ($t === NULL) {
  25              $t = time();
  26          }
  27          return gmstrftime('%Y%m%d', $t);
  28      }
  29  
  30      static function generate_guid() {
  31          // Implemented as per the Network Working Group draft on UUIDs and GUIDs
  32  
  33          // These two octets get special treatment
  34          $time_hi_and_version       = sprintf('%02x', (1 << 6) + mt_rand(0, 15)); // 0100 plus 4 random bits
  35          $clock_seq_hi_and_reserved = sprintf('%02x', (1 << 7) + mt_rand(0, 63)); // 10 plus 6 random bits
  36  
  37          // Need another 14 random octects
  38          $pool = '';
  39          for($i = 0; $i < 7; ++$i) {
  40              $pool .= sprintf('%04x', mt_rand(0, 65535));
  41          }
  42  
  43          // time_low = 4 octets
  44          $random  = substr($pool, 0, 8).'-';
  45  
  46          // time_mid = 2 octets
  47          $random .= substr($pool, 8, 4).'-';
  48  
  49          // time_high_and_version = 2 octets
  50          $random .= $time_hi_and_version.substr($pool, 12, 2).'-';
  51  
  52          // clock_seq_high_and_reserved = 1 octet
  53          $random .= $clock_seq_hi_and_reserved;
  54  
  55          // clock_seq_low = 1 octet
  56          $random .= substr($pool, 13, 2).'-';
  57  
  58          // node = 6 octets
  59          $random .= substr($pool, 14, 12);
  60  
  61          return $random;
  62      }
  63  }
  64