001 /** 002 * Copyright 2010 The Kuali Foundation Licensed under the 003 * Educational Community License, Version 2.0 (the "License"); you may 004 * not use this file except in compliance with the License. You may 005 * obtain a copy of the License at 006 * 007 * http://www.osedu.org/licenses/ECL-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, 010 * software distributed under the License is distributed on an "AS IS" 011 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 012 * or implied. See the License for the specific language governing 013 * permissions and limitations under the License. 014 */ 015 016 package org.kuali.student.r1.common.validator; 017 018 import org.kuali.student.r2.common.util.date.DateFormatters; 019 import org.kuali.student.r2.common.util.date.KSDateTimeFormatter; 020 021 import java.util.Date; 022 023 @Deprecated 024 public class ServerDateParser implements DateParser { 025 026 private static ThreadLocal<KSDateTimeFormatter[]> formats = new ThreadLocal<KSDateTimeFormatter[]>() { 027 028 protected KSDateTimeFormatter[] initialValue() { 029 return new KSDateTimeFormatter[] { 030 new KSDateTimeFormatter("yyyy-MM-dd'T'HH:mm:ss.SSSZ"), 031 new KSDateTimeFormatter("yyyy-MM-dd"), 032 new KSDateTimeFormatter("yyyy-MMM-dd"), 033 new KSDateTimeFormatter("dd-MM-yyyy"), 034 new KSDateTimeFormatter("dd-MMM-yyyy") 035 }; 036 } 037 038 }; 039 040 041 public Date parseDate(String input) { 042 Date result = null; 043 044 for (KSDateTimeFormatter format : formats.get()) { 045 try { 046 result = format.parse(input); 047 } catch (Exception e) { 048 // just eat it 049 } 050 if (result != null) { 051 break; 052 } 053 054 } 055 056 if (result == null) { 057 throw new DateParseException("Invalid date value: " + input); 058 } 059 060 return result; 061 } 062 063 /** 064 * @see org.kuali.student.r1.common.validator.old.DateParser#toString(java.util.Date) 065 */ 066 @Override 067 public String toString(Date date) { 068 String result = null; 069 result = DateFormatters.SERVER_DATE_PARSER_FORMATTER.format(date); 070 071 return result; 072 } 073 }