001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2003-2006, Geotools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.data.vpf.io;
017:
018: import java.text.ParseException;
019: import java.text.SimpleDateFormat;
020: import java.util.Calendar;
021: import java.util.Date;
022: import java.util.TimeZone;
023:
024: /**
025: * VPFDate.java Created: Tue Jan 28 20:50:51 2003
026: *
027: * @author <a href="mailto:kobit@users.sourceforge.net">Artur Hefczyc</a>
028: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/vpf/src/main/java/org/geotools/data/vpf/io/VPFDate.java $
029: *
030: */
031: public class VPFDate {
032: /**
033: * Describe variable <code>sdf</code> here.
034: *
035: */
036: private SimpleDateFormat sdf = null;
037:
038: /**
039: * Describe variable <code>dateBin</code> here.
040: *
041: */
042: private byte[] dateBin = null;
043:
044: /**
045: * Creates a new <code>VPFDate</code> instance.
046: *
047: * @param date a <code>byte[]</code> value
048: */
049: public VPFDate(byte[] date) {
050: dateBin = (byte[]) date.clone();
051: initialize();
052: }
053:
054: /**
055: * Creates a new <code>VPFDate</code> instance.
056: *
057: * @param date a <code>String</code> value
058: */
059: public VPFDate(String date) {
060: dateBin = new byte[date.length()];
061:
062: for (int i = 0; i < date.length(); i++) {
063: dateBin[i] = (byte) date.charAt(i);
064: }
065:
066: initialize();
067: }
068:
069: /**
070: * Describe <code>initialize</code> method here.
071: *
072: */
073: private void initialize() {
074: for (int i = 0; i < dateBin.length; i++) {
075: if ((char) dateBin[i] == ' ') {
076: dateBin[i] = (byte) '0';
077: }
078: }
079:
080: sdf = new SimpleDateFormat("yyyyMMddHHmmss");
081:
082: StringBuffer sb = new StringBuffer();
083:
084: for (int i = 15; i < dateBin.length; i++) {
085: char cr = (char) dateBin[i];
086:
087: if (i == 18) {
088: sb.append(':');
089: }
090:
091: sb.append(cr);
092: }
093:
094: sdf.setTimeZone(TimeZone.getTimeZone(sb.toString()));
095: }
096:
097: /**
098: * Describe <code>toString</code> method here.
099: *
100: * @return a <code>String</code> value
101: */
102: public String toString() {
103: StringBuffer sb = new StringBuffer(dateBin.length);
104:
105: for (int i = 0; i < dateBin.length; i++) {
106: sb.append((char) dateBin[i]);
107: }
108:
109: return sb.toString();
110: }
111:
112: /**
113: * Describe <code>getDate</code> method here.
114: *
115: * @return a <code>Date</code> value
116: */
117: public Date getDate() {
118: try {
119: return sdf.parse(toString());
120: } catch (ParseException e) {
121: e.printStackTrace();
122: }
123:
124: return null;
125: }
126:
127: /**
128: * Describe <code>getCalendar</code> method here.
129: *
130: * @return a <code>Calendar</code> value
131: */
132: public Calendar getCalendar() {
133: try {
134: sdf.parse(toString());
135:
136: return sdf.getCalendar();
137: } catch (ParseException e) {
138: e.printStackTrace();
139: }
140:
141: return null;
142: }
143: }
|