Bug 2366 - Effective statments impl merge, retest & bugfix
[yangtools.git] / yang / yang-common / src / main / java / org / opendaylight / yangtools / yang / common / SimpleDateFormatUtil.java
index dbffc30acc292e83ba3d2ac8d6ec94065a8cdc64..0ffc0bec1d4e30cdf1df7166f5fdb73138bfded0 100644 (file)
@@ -8,10 +8,49 @@
 
 package org.opendaylight.yangtools.yang.common;
 
+import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.util.Date;
 
 public final class SimpleDateFormatUtil {
 
+    /**
+     * revision format according to Yang spec
+     */
+    private static final String REVISION_SIMPLE_DATE = "yyyy-MM-dd";
+
+    /**
+     * default Yang date that is used when date is not present
+     */
+    private static final String DEFAULT_DATE = "1970-01-01";
+
+    /**
+     * {@link SimpleDateFormatUtil#DEFAULT_DATE} for revision statement
+     */
+    public static final Date DEFAULT_DATE_REV;
+
+    /**
+     * {@link SimpleDateFormatUtil#DEFAULT_DATE} for import statement
+     */
+    public static final Date DEFAULT_DATE_IMP;
+
+    /**
+     * {@link SimpleDateFormatUtil#DEFAULT_DATE} for belongs-to statement
+     */
+    public static final Date DEFAULT_BELONGS_TO_DATE;
+
+    static {
+        final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(REVISION_SIMPLE_DATE);
+
+        try {
+            DEFAULT_DATE_REV = simpleDateFormat.parse(DEFAULT_DATE);
+            DEFAULT_DATE_IMP = simpleDateFormat.parse(DEFAULT_DATE);
+            DEFAULT_BELONGS_TO_DATE = simpleDateFormat.parse(DEFAULT_DATE);
+        } catch (final ParseException e) {
+            throw new ExceptionInInitializerError(e);
+        }
+    }
+
     private SimpleDateFormatUtil() {
         throw new UnsupportedOperationException("Utility class should not be instantiated");
     }
@@ -20,13 +59,13 @@ public final class SimpleDateFormatUtil {
 
         @Override
         protected SimpleDateFormat initialValue() {
-            return new SimpleDateFormat("yyyy-MM-dd");
-        };
+            return new SimpleDateFormat(REVISION_SIMPLE_DATE);
+        }
 
         @Override
-        public void set(SimpleDateFormat value) {
+        public void set(final SimpleDateFormat value) {
             throw new UnsupportedOperationException();
-        };
+        }
 
     };