GSON now uses a unified date format to when converting dates to/from JSON

This commit is contained in:
y20k 2017-01-18 09:58:04 +01:00
parent 28e9fb7991
commit d38adb62d9
3 changed files with 23 additions and 23 deletions

16
AUTHORS.md Normal file
View file

@ -0,0 +1,16 @@
AUTHORS
=======
### Development
Trackbook is designed, developed and maintained by: [y20k](https://github.com/y20k)
### Translations
German version: [y20k](https://github.com/y20k)
### Testing
Thanks for finding all those bugs:
* [collectorgeneral](https://github.com/collectorgeneral)
### Want to help?
Please check out the notes in [CONTRIBUTE.md](https://github.com/y20k/trackbook/blob/master/CONTRIBUTE.md) first.

View file

@ -24,7 +24,6 @@ import org.y20k.trackbook.helpers.LocationHelper;
import org.y20k.trackbook.helpers.LogHelper;
import org.y20k.trackbook.helpers.TrackbookKeys;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
@ -70,13 +69,6 @@ public class Track implements TrackbookKeys, Parcelable {
mStepCount = in.readFloat();
mRecordingStart = new Date(in.readLong());
mRecordingStop = new Date(in.readLong());
// TODO remove logging
String recordingStart = DateFormat.getDateInstance(DateFormat.SHORT).format(mRecordingStart) + " " +
DateFormat.getTimeInstance(DateFormat.SHORT).format(mRecordingStart);
String recordingStop = DateFormat.getDateInstance(DateFormat.SHORT).format(mRecordingStop) + " " +
DateFormat.getTimeInstance(DateFormat.SHORT).format(mRecordingStop);
LogHelper.v(LOG_TAG, "Track recreated from parcel. Start: " + recordingStart + " | Stop: " + recordingStop);
}
@ -126,11 +118,6 @@ public class Track implements TrackbookKeys, Parcelable {
/* Sets end time and date of recording */
public void setRecordingEnd () {
mRecordingStop = GregorianCalendar.getInstance().getTime();;
// TODO remove logging
String recordingStop = DateFormat.getDateInstance(DateFormat.SHORT).format(mRecordingStop) + " " +
DateFormat.getTimeInstance(DateFormat.SHORT).format(mRecordingStop);
LogHelper.v(LOG_TAG, "Saving date and time to track: " + recordingStop);
}
@ -235,14 +222,6 @@ public class Track implements TrackbookKeys, Parcelable {
parcel.writeFloat(mStepCount);
parcel.writeLong(mRecordingStart.getTime());
parcel.writeLong(mRecordingStop.getTime());
// TODO remove logging
String recordingStart = DateFormat.getDateInstance(DateFormat.SHORT).format(mRecordingStart) + " " +
DateFormat.getTimeInstance(DateFormat.SHORT).format(mRecordingStart);
String recordingStop = DateFormat.getDateInstance(DateFormat.SHORT).format(mRecordingStop) + " " +
DateFormat.getTimeInstance(DateFormat.SHORT).format(mRecordingStop);
LogHelper.v(LOG_TAG, "Track writing to parcel. Start: " + recordingStart + " | Stop: " + recordingStop);
}

View file

@ -23,6 +23,7 @@ import android.support.v4.os.EnvironmentCompat;
import android.widget.Toast;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.y20k.trackbook.R;
import org.y20k.trackbook.core.Track;
@ -116,7 +117,9 @@ public class StorageHelper implements TrackbookKeys {
File file = new File(mFolder.toString() + "/" + fileName);
// convert track to JSON
Gson gson = new Gson();
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.setDateFormat("M/d/yy hh:mm a");
Gson gson = gsonBuilder.create();
String json = gson.toJson(track);
// write track
@ -174,7 +177,9 @@ public class StorageHelper implements TrackbookKeys {
}
// get track from JSON
Gson gson = new Gson();
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.setDateFormat("M/d/yy hh:mm a");
Gson gson = gsonBuilder.create();
return gson.fromJson(sb.toString(), Track.class);
} catch (IOException e) {