Navigation Menu

Skip to content

Commit

Permalink
follow the user's configuration of "24 hour time format" when
Browse files Browse the repository at this point in the history
stringifying a Javascript Date using toLocaleString and
toLocaleTimeString. TIMOB-3742
  • Loading branch information
marshall committed Jun 21, 2011
1 parent 494275b commit 671fff2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
Binary file modified android/titanium/lib/js-debug.jar
Binary file not shown.
Binary file modified android/titanium/lib/js.jar
Binary file not shown.
Binary file modified android/titanium/lib/smalljs.jar
Binary file not shown.
Expand Up @@ -287,6 +287,8 @@ public void onOrientationChanged(int orientation) {
}
};

TiPlatformHelper.initializeRhinoDateFormats(this);

layout = createLayout();
super.onCreate(savedInstanceState);
getTiApp().setWindowHandler(this);
Expand Down
@@ -1,6 +1,6 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2010 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2009-2011 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
Expand All @@ -10,7 +10,12 @@
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Method;
import java.text.DateFormat;
import java.text.FieldPosition;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Currency;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
Expand All @@ -19,6 +24,7 @@

import org.appcelerator.titanium.ITiAppInfo;
import org.appcelerator.titanium.TiApplication;
import org.mozilla.javascript.NativeDate;

import android.Manifest;
import android.app.Activity;
Expand Down Expand Up @@ -126,6 +132,31 @@ public static synchronized void intializeDisplayMetrics(Activity activity)
}
}

public static void initializeRhinoDateFormats(Context context)
{
// http://jira.appcelerator.org/browse/TIMOB-3742
// toLocaleTimeString / toLocaleString don't honor the user's 24 hour setting
if (NativeDate.localeDateFormatter != null) return;

NativeDate.localeDateFormatter = android.text.format.DateFormat.getLongDateFormat(context);
NativeDate.localeTimeFormatter = android.text.format.DateFormat.getTimeFormat(context);

SimpleDateFormat timeFormat = (SimpleDateFormat)
DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);

if (android.text.format.DateFormat.is24HourFormat(context)) {
if (timeFormat != null) {
String pattern = timeFormat.toLocalizedPattern();
// Switch to 24 hour format: h->H, AM/PM goes away
pattern = pattern.replaceAll("h", "H");
pattern = pattern.replaceAll("a", "");
timeFormat = new SimpleDateFormat(pattern, Locale.getDefault());
}
}

NativeDate.localeDateTimeFormatter = timeFormat;
}

public static ITiAppInfo getAppInfo() {
return TiApplication.getInstance().getAppInfo();
}
Expand Down

0 comments on commit 671fff2

Please sign in to comment.