2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.yangtools.yang.common;
11 import java.text.ParseException;
12 import java.text.SimpleDateFormat;
13 import java.util.Date;
15 public final class SimpleDateFormatUtil {
18 * revision format according to Yang spec
20 private static final String REVISION_SIMPLE_DATE = "yyyy-MM-dd";
23 * default Yang date that is used when date is not present
25 private static final String DEFAULT_DATE = "1970-01-01";
28 * {@link SimpleDateFormatUtil#DEFAULT_DATE} for revision statement
30 public static final Date DEFAULT_DATE_REV;
33 * {@link SimpleDateFormatUtil#DEFAULT_DATE} for import statement
35 public static final Date DEFAULT_DATE_IMP;
38 * {@link SimpleDateFormatUtil#DEFAULT_DATE} for belongs-to statement
40 public static final Date DEFAULT_BELONGS_TO_DATE;
43 final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(REVISION_SIMPLE_DATE);
46 DEFAULT_DATE_REV = simpleDateFormat.parse(DEFAULT_DATE);
47 DEFAULT_DATE_IMP = simpleDateFormat.parse(DEFAULT_DATE);
48 DEFAULT_BELONGS_TO_DATE = simpleDateFormat.parse(DEFAULT_DATE);
49 } catch (final ParseException e) {
50 throw new ExceptionInInitializerError(e);
54 private SimpleDateFormatUtil() {
55 throw new UnsupportedOperationException("Utility class should not be instantiated");
58 private static final ThreadLocal<SimpleDateFormat> REVISION_FORMAT = new ThreadLocal<SimpleDateFormat>() {
61 protected SimpleDateFormat initialValue() {
62 return new SimpleDateFormat(REVISION_SIMPLE_DATE);
66 public void set(final SimpleDateFormat value) {
67 throw new UnsupportedOperationException();
72 public static SimpleDateFormat getRevisionFormat() {
73 return REVISION_FORMAT.get();