mirror of
https://gitlab.easter-eggs.com/ee/ldapsaisie.git
synced 2024-11-22 09:59:06 +01:00
LSldap: add formatDate() method
This commit is contained in:
parent
4ec5769276
commit
1825ce429e
1 changed files with 21 additions and 0 deletions
|
@ -332,6 +332,27 @@ class LSldap extends LSlog_staticLoggerClass {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a Datetime object as LDAP date string
|
||||
*
|
||||
* @param DateTime|null $datetime The DateTime object to format (optional, default: now)
|
||||
* @param bool $utc Force UTC timezone (optional, default: false)
|
||||
*
|
||||
* @return string|false LDAP date string, or false
|
||||
*/
|
||||
public static function formatDate($datetime=null, $utc=true) {
|
||||
if (is_null($datetime))
|
||||
$datetime = new DateTime('now');
|
||||
elseif (!$datetime instanceof DateTime)
|
||||
return false;
|
||||
$datetime -> setTimezone(timezone_open($utc?'utc':date_default_timezone_get()));
|
||||
$datetime_string = $datetime -> format('YmdHis.uO');
|
||||
|
||||
// Replace +0000 or -0000 end by Z
|
||||
$datetime_string = preg_replace('/[\+\-]0000$/', 'Z', $datetime_string);
|
||||
return $datetime_string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an attribute exists in specified attributes collection
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue