Skip to content

Commit

Permalink
Reading Date
Browse files Browse the repository at this point in the history
  • Loading branch information
Xavier GOUCHET committed Mar 21, 2013
1 parent 58fcaf7 commit 1a1fd31
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions Axel/src/fr/xgouchet/xmleditor/data/plist/XMLPlistParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.NotSerializableException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Map.Entry;

import java.text.DateFormat;
import android.util.Log;
import fr.xgouchet.plist.PlistParser;
import fr.xgouchet.plist.data.PArray;
import fr.xgouchet.plist.data.PBoolean;
import fr.xgouchet.plist.data.PDate;
import fr.xgouchet.plist.data.PDict;
import fr.xgouchet.plist.data.PInt;
import fr.xgouchet.plist.data.PObject;
Expand All @@ -23,6 +28,10 @@

public class XMLPlistParser extends XmlTreeParser {

private static final String ISO8601_PATTERN = "yyyy-MM-dd'T'HH:mm:ss'Z'";
private static final DateFormat ISO8601 = new SimpleDateFormat(
ISO8601_PATTERN, Locale.US);

public static final XmlNode parseXmlTree(File file) {

XMLPlistParser parser = new XMLPlistParser();
Expand Down Expand Up @@ -90,6 +99,9 @@ private void convertPObject(PObject object) {
case DICT:
convertPDict((PDict) object);
break;
case DATE:
convertPDate((PDate) object);
break;
default:
Log.w("Axel", "Missing PList item " + type.name());
break;
Expand Down Expand Up @@ -165,4 +177,15 @@ private void convertPDict(PDict dict) {

onCloseElement();
}

private void convertPDate(PDate date) {
onCreateElement(XmlNode.createElement("date"));

// Log.i("Axel", "Converting date " + date.getValue());

String value = ISO8601.format(new Date(date.getValue()));
onCreateElement(XmlNode.createText(value));

onCloseElement();
}
}
2 changes: 1 addition & 1 deletion PList

0 comments on commit 1a1fd31

Please sign in to comment.