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.common.ui.client.validator; 017 018 import java.util.Date; 019 020 import org.kuali.student.r1.common.validator.DateParseException; 021 import org.kuali.student.r1.common.validator.DateParser; 022 023 import com.google.gwt.i18n.client.DateTimeFormat; 024 025 @Deprecated 026 public class ClientDateParser implements DateParser { 027 DateTimeFormat[] formats = {DateTimeFormat.getFormat("yyyy-MM-dd"), DateTimeFormat.getFormat("yyyy-MM-ddTHH:mm:ss,SSS")}; 028 029 public Date parseDate(String input) { 030 Date result = null; 031 032 for (DateTimeFormat format : formats) { 033 try { 034 result = format.parseStrict(input); 035 } catch (IllegalArgumentException e) { 036 // just eat it 037 } 038 if (result != null) { 039 break; 040 } 041 042 } 043 044 if (result == null) { 045 throw new DateParseException("Invalid date value: " + input); 046 } 047 048 return result; 049 } 050 051 public String toString(Date date){ 052 String result = null; 053 DateTimeFormat format = DateTimeFormat.getFormat("yyyy-MM-ddTHH:mm:ss,SSS"); 054 result = format.format(date); 055 056 return result; 057 } 058 059 060 }