Make simpleDate independent of locale to prevent different results in different locales.

This commit is contained in:
GaidamakUA 2015-12-01 11:36:40 +02:00
parent 5b8e075f61
commit 25bcf676b5
6 changed files with 45 additions and 40 deletions

View file

@ -779,7 +779,7 @@ public class GPXUtilities {
public static String writeGpx(Writer output, GPXFile file, OsmandApplication ctx) {
try {
SimpleDateFormat format = new SimpleDateFormat(GPX_TIME_FORMAT);
SimpleDateFormat format = new SimpleDateFormat(GPX_TIME_FORMAT, Locale.US);
format.setTimeZone(TimeZone.getTimeZone("UTC"));
XmlSerializer serializer = PlatformUtil.newSerializer();
serializer.setOutput(output);
@ -960,7 +960,7 @@ public class GPXUtilities {
public static GPXFile loadGPXFile(Context ctx, InputStream f) {
GPXFile res = new GPXFile();
SimpleDateFormat format = new SimpleDateFormat(GPX_TIME_FORMAT);
SimpleDateFormat format = new SimpleDateFormat(GPX_TIME_FORMAT, Locale.US);
format.setTimeZone(TimeZone.getTimeZone("UTC"));
try {
XmlPullParser parser = PlatformUtil.newXMLPullParser();

View file

@ -33,6 +33,7 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
public class ContributionVersionActivity extends OsmandListActivity {
@ -48,7 +49,7 @@ public class ContributionVersionActivity extends OsmandListActivity {
private Date currentInstalledDate;
private List<OsmAndBuild> downloadedBuilds = new ArrayList<OsmAndBuild>();
private SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
private SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy", Locale.US);
private File pathToDownload;
private OsmAndBuild currentSelectedBuild = null;

View file

@ -1,12 +1,9 @@
package net.osmand.plus.activities;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.text.format.DateFormat;
import net.osmand.PlatformUtil;
import net.osmand.data.LatLon;
@ -25,10 +22,14 @@ import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import org.apache.commons.logging.Log;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.text.format.DateFormat;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
public class SavingTrackHelper extends SQLiteOpenHelper {
@ -194,7 +195,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
File fout = new File(dir, f + ".gpx"); //$NON-NLS-1$
if (!data.get(f).isEmpty()) {
WptPt pt = data.get(f).findPointToShow();
String fileName = f + "_" + new SimpleDateFormat("HH-mm_EEE").format(new Date(pt.time)); //$NON-NLS-1$
String fileName = f + "_" + new SimpleDateFormat("HH-mm_EEE", Locale.US).format(new Date(pt.time)); //$NON-NLS-1$
fout = new File(dir, fileName + ".gpx"); //$NON-NLS-1$
int ind = 1;
while (fout.exists()) {

View file

@ -1,15 +1,6 @@
package net.osmand.plus.download;
import static net.osmand.IndexConstants.BINARY_MAP_INDEX_EXT;
import java.io.File;
import java.io.IOException;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import android.content.Context;
import net.osmand.AndroidUtils;
import net.osmand.IndexConstants;
@ -22,10 +13,20 @@ import net.osmand.util.Algorithms;
import org.xmlpull.v1.XmlPullParser;
import android.content.Context;
import java.io.File;
import java.io.IOException;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import static net.osmand.IndexConstants.BINARY_MAP_INDEX_EXT;
public class DownloadActivityType {
private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd.MM.yyyy");
private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd.MM.yyyy", Locale.US);
private static Map<String, DownloadActivityType> byTag = new HashMap<>();
public static final DownloadActivityType NORMAL_FILE =

View file

@ -34,6 +34,7 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
/**
* @author Koen Rabaey
@ -281,7 +282,7 @@ public class GpxImportHelper {
private File getFileToSave(final String fileName, final File importDir, final GPXUtilities.WptPt pt) {
final StringBuilder builder = new StringBuilder(fileName);
if ("".equals(fileName)) {
builder.append("import_").append(new SimpleDateFormat("HH-mm_EEE").format(new Date(pt.time))).append(GPX_SUFFIX); //$NON-NLS-1$
builder.append("import_").append(new SimpleDateFormat("HH-mm_EEE", Locale.US).format(new Date(pt.time))).append(GPX_SUFFIX); //$NON-NLS-1$
}
if (fileName.endsWith(KML_SUFFIX)) {
builder.replace(builder.length() - KML_SUFFIX.length(), builder.length(), GPX_SUFFIX);

View file

@ -1,5 +1,16 @@
package net.osmand.plus.osmo;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import net.osmand.PlatformUtil;
import net.osmand.plus.osmo.OsMoService.SessionInfo;
import org.apache.commons.logging.Log;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.InetSocketAddress;
@ -12,22 +23,12 @@ import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;
import net.osmand.PlatformUtil;
import net.osmand.plus.osmo.OsMoService.SessionInfo;
import org.apache.commons.logging.Log;
import org.json.JSONException;
import org.json.JSONObject;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
public class OsMoThread {
// private static String TRACKER_SERVER = "srv.osmo.mobi";
// private static int TRACKER_PORT = 3245;
@ -63,7 +64,7 @@ public class OsMoThread {
private ByteBuffer pendingReadCommand = ByteBuffer.allocate(2048);
private LinkedList<String> queueOfMessages = new LinkedList<String>();
private SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
private SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss", Locale.US);
private ConcurrentLinkedQueue<String> lastCommands = new ConcurrentLinkedQueue<String>();
private final static int STACK_CMD = 30;