Improve tokens
[lgpl/argeo-commons.git] / org.argeo.enterprise / src / org / argeo / naming / NamingUtils.java
index cb93e825786d56f3c90edc20f7759743cb793d13..5a868ddb42b885afbad49925c247407ff3907182 100644 (file)
@@ -19,6 +19,7 @@ import java.util.List;
 import java.util.Map;
 
 public class NamingUtils {
+       /** As per https://tools.ietf.org/html/rfc4517#section-3.3.13 */
        private final static DateTimeFormatter utcLdapDate = DateTimeFormatter.ofPattern("uuuuMMddHHmmssX")
                        .withZone(ZoneOffset.UTC);
 
@@ -31,6 +32,15 @@ public class NamingUtils {
                }
        }
 
+       /** @return null if not parseable */
+       public static ZonedDateTime ldapDateToZonedDateTime(String ldapDate) {
+               try {
+                       return OffsetDateTime.parse(ldapDate, utcLdapDate).toZonedDateTime();
+               } catch (DateTimeParseException e) {
+                       return null;
+               }
+       }
+
        public static Calendar ldapDateToCalendar(String ldapDate) {
                OffsetDateTime instant = OffsetDateTime.parse(ldapDate, utcLdapDate);
                GregorianCalendar calendar = new GregorianCalendar();