ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 $duration = 'P';
64 if (!empty($d->y)) {
65 $duration .= "{$d->y}Y";
66 }
67 if (!empty($d->m)) {
68 $duration .= "{$d->m}M";
69 }
70 if (!empty($d->d)) {
71 $duration .= "{$d->d}D";
72 }
73 if (!empty($d->h) || !empty($d->i) || !empty($d->s)) {
74 $duration .= 'T';
75 if (!empty($d->h)) {
76 $duration .= "{$d->h}H";
77 }
78 if (!empty($d->i)) {
79 $duration .= "{$d->i}M";
80 }
81 if (!empty($d->s)) {
82 $duration .= "{$d->s}S";
83 }
84 // ToDo: nervt!
85 /*
86 if (!empty($d->f)) {
87 if (!empty($d->s)) {
88 $s = $d->s + $d->f;
89 }
90 else {
91 $s = $d->f;
92 }
93 $duration .= "{$s}S";
94 }
95 else
96 {
97 if (!empty($d->s)) {
98 $duration .= "S";
99 }
100 }
101 */
102 }
103 if ($duration === 'P') {
104 $duration = 'PT0S'; // Empty duration (zero seconds)
105 }
106 return $duration;
107 }
108}
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
static fromIliasDateTime(ilDateTime $dateTime)
const RFC3336_EXTENDED_FIXED_USING_u_INSTEAD_OF_v
static dateIntervalToISO860Duration(\DateInterval $d)
static fromXapiTimestamp($xapiTimestamp)
@classDescription Date and time handling
get($a_format, $a_format_str='', $a_tz='')
get formatted date
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296