/* * PinDroid - http://code.google.com/p/PinDroid/ * * Copyright (C) 2010 Matt Schmidt * * PinDroid is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published * by the Free Software Foundation; either version 3 of the License, * or (at your option) any later version. * * PinDroid is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with PinDroid; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ package com.pindroid.util; import android.annotation.SuppressLint; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.TimeZone; @SuppressLint("SimpleDateFormat") public class DateParser { public static final TimeZone tz = TimeZone.getTimeZone("GMT"); public static final Calendar c = Calendar.getInstance(tz); public static Date parse( String input ) throws java.text.ParseException { //NOTE: SimpleDateFormat uses GMT[-+]hh:mm for the TZ which breaks //things a bit. Before we go on we have to repair this. SimpleDateFormat df = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ssz" ); //this is zero time so we need to add that TZ indicator for if ( input.endsWith( "Z" ) ) { input = input.substring( 0, input.length() - 1) + "GMT-00:00"; } else { int inset = 6; String s0 = input.substring( 0, input.length() - inset ); String s1 = input.substring( input.length() - inset, input.length() ); input = s0 + "GMT" + s1; } return df.parse( input ); } public static long parseTime( String input ) { c.clear(); c.set(IntUtils.parseUInt(input.substring(0, 4)), IntUtils.parseUInt(input.substring(5, 7)) - 1, IntUtils.parseUInt(input.substring(8, 10)), IntUtils.parseUInt(input.substring(11, 13)), IntUtils.parseUInt(input.substring(14, 16)), IntUtils.parseUInt(input.substring(17, 19))); return c.getTimeInMillis(); } }