ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilCmiXapiDateTime.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 
16 {
17  // DateTime::RFC3339_EXTENDED resolves to Y-m-d\TH:i:s.vP
18  // note the v at the end -> this works with PHP 7.3
19  // but not with PHP 7.2, 7.1 and probably not with versions below
20 
22 
27  public function toXapiTimestamp()
28  {
29  $phpDateTime = new DateTime();
30  $phpDateTime->setTimestamp($this->get(IL_CAL_UNIX));
31 
32  return $phpDateTime->format(self::RFC3336_EXTENDED_FIXED_USING_u_INSTEAD_OF_v);
33  }
34 
40  public static function fromXapiTimestamp($xapiTimestamp)
41  {
42  $phpDateTime = DateTime::createFromFormat(
43  self::RFC3336_EXTENDED_FIXED_USING_u_INSTEAD_OF_v,
44  $xapiTimestamp
45  );
46 
47  $unixTimestamp = $phpDateTime->getTimestamp();
48 
49  return new self($unixTimestamp, IL_CAL_UNIX);
50  }
51 
57  public static function fromIliasDateTime(ilDateTime $dateTime)
58  {
59  return new self($dateTime->get(IL_CAL_UNIX), IL_CAL_UNIX);
60  }
61 
62  public static function dateIntervalToISO860Duration(\DateInterval $d)
63  {
64  $duration = 'P';
65  if (!empty($d->y)) {
66  $duration .= "{$d->y}Y";
67  }
68  if (!empty($d->m)) {
69  $duration .= "{$d->m}M";
70  }
71  if (!empty($d->d)) {
72  $duration .= "{$d->d}D";
73  }
74  if (!empty($d->h) || !empty($d->i) || !empty($d->s)) {
75  $duration .= 'T';
76  if (!empty($d->h)) {
77  $duration .= "{$d->h}H";
78  }
79  if (!empty($d->i)) {
80  $duration .= "{$d->i}M";
81  }
82  if (!empty($d->s)) {
83  $duration .= "{$d->s}S";
84  }
85  // ToDo: nervt!
86  /*
87  if (!empty($d->f)) {
88  if (!empty($d->s)) {
89  $s = $d->s + $d->f;
90  }
91  else {
92  $s = $d->f;
93  }
94  $duration .= "{$s}S";
95  }
96  else
97  {
98  if (!empty($d->s)) {
99  $duration .= "S";
100  }
101  }
102  */
103  }
104  if ($duration === 'P') {
105  $duration = 'PT0S'; // Empty duration (zero seconds)
106  }
107  return $duration;
108  }
109 }
const RFC3336_EXTENDED_FIXED_USING_u_INSTEAD_OF_v
const IL_CAL_UNIX
get($a_format, $a_format_str='', $a_tz='')
get formatted date
static fromIliasDateTime(ilDateTime $dateTime)
static dateIntervalToISO860Duration(\DateInterval $d)
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
static fromXapiTimestamp($xapiTimestamp)