com.abubusoft.kripton.common.CalendarUtils Maven / Gradle / Ivy
/*******************************************************************************
* Copyright 2015, 2016 Francesco Benincasa.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
package com.abubusoft.kripton.common;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;
// TODO: Auto-generated Javadoc
/**
* The Class CalendarUtils.
*/
public class CalendarUtils {
/** The full. */
public static String FULL = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
/** The long. */
public static String LONG = "yyyy-MM-dd HH:mm:ss z";
/** The normal. */
public static String NORMAL = "yyyy-MM-dd z";
/** The short. */
public static String SHORT = "yyyy-MM-dd";
/** The time zone. */
public static String TIME_ZONE = "GMT";
/**
* Read.
*
* @param value the value
* @return the calendar
*/
public static Calendar read(String value) {
if (value==null) return null;
Date date=DateUtils.read(value);
Calendar calendar=Calendar.getInstance();
calendar.setTime(date);
return calendar;
}
/**
* Write.
*
* @param value the value
* @return the string
*/
public static String write(Calendar value) {
if (value==null) return null;
return DateUtils.write(value.getTime());
}
/**
* Gets the pattern.
*
* @param text the text
* @return the pattern
*/
static String getPattern(String text) {
int length = text.length();
if (length > 23) {
return FULL;
}
if (length > 20) {
return LONG;
}
if (length > 11) {
return NORMAL;
}
return SHORT;
}
/**
* The Class ThreadLocalDateFormatter.
*/
public static class ThreadLocalDateFormatter {
/** The Constant FORMATTERS. */
private static final ThreadLocal