From 8dbbda801a162f7af36368f4858557ca4c850d62 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Thu, 10 Jun 2021 19:01:22 +0200 Subject: [PATCH] LSattr_ldap::naiveDate: Add format option --- .../LSattr_ldap/LSattr_ldap_naiveDate.docbook | 31 +++++++++++++++++++ .../class/class.LSattr_ldap_naiveDate.php | 16 +++++++--- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/doc/conf/LSattribute/LSattr_ldap/LSattr_ldap_naiveDate.docbook b/doc/conf/LSattribute/LSattr_ldap/LSattr_ldap_naiveDate.docbook index 4ed8f4c8..e7432627 100644 --- a/doc/conf/LSattribute/LSattr_ldap/LSattr_ldap_naiveDate.docbook +++ b/doc/conf/LSattribute/LSattr_ldap/LSattr_ldap_naiveDate.docbook @@ -6,4 +6,35 @@ une timezone, cependant celle-ci sera complètement ignorée. Ce type peut-être utilisé à la place du type &LSattr_ldap_date;. + + Structure array ( + 'format' => '[Format de stockage]', // Default : "%Y%m%d%H%M%SZ" +), +...]]> + + + + Paramètres de configuration + + + format + + Format de stockage de la date dans l'annuaire. Ce format est composé à + partir des motifs clés gérés par la fonction strftime() + de &php;. Pour plus d'information, consulter + la documentation officielle. + La valeur par défaut est %Y%m%d%H%M%SZ, + correspondant à la syntaxe Generalized Time (sans les + micro-secondes) telle que définie dans la + RFC4517. Exemples : + 20091206230506Z + (=2009/12/06 23:05:66 UTC). + + + + + + + diff --git a/src/includes/class/class.LSattr_ldap_naiveDate.php b/src/includes/class/class.LSattr_ldap_naiveDate.php index cd979d3c..e31cb874 100644 --- a/src/includes/class/class.LSattr_ldap_naiveDate.php +++ b/src/includes/class/class.LSattr_ldap_naiveDate.php @@ -28,8 +28,6 @@ */ class LSattr_ldap_naiveDate extends LSattr_ldap { - const FORMAT = "%Y%m%d%H%M%S"; - /** * Return the display value of the attribute after handling is LDAP type * @@ -40,7 +38,7 @@ class LSattr_ldap_naiveDate extends LSattr_ldap { public function getDisplayValue($data) { $retval = array(); foreach(ensureIsArray($data) as $val) { - $date = strptime($val, self::FORMAT); + $date = strptime($val, $this -> getFormat()); if (is_array($date)) { $retval[] = mktime( $date['tm_hour'], @@ -65,9 +63,19 @@ class LSattr_ldap_naiveDate extends LSattr_ldap { public function getUpdateData($data) { $retval = array(); foreach(ensureIsArray($data) as $val) { - $retval[] = strftime(self::FORMAT, $val).'Z'; + $retval[] = strftime($this -> getFormat(), $val); } return $retval; } + + /** + * Return the storage format of the date (as accept by strptime()/strftime()) + * + * @retval string the storage format of the date + **/ + public function getFormat() { + return $this -> getConfig('ldap_options.format', "%Y%m%d%H%M%SZ"); + } + }