Changes to date string creation

pull/14/head
Jimmy Scott 12 years ago
parent 6a2561093c
commit af0c86b8a9

@ -6,6 +6,7 @@
package com.todoroo.andlib.utility; package com.todoroo.andlib.utility;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
@ -108,6 +109,12 @@ public class DateUtilities {
return new SimpleDateFormat(value).format(date); return new SimpleDateFormat(value).format(date);
} }
/* Returns true if search string is in sortedValues */
private static boolean arrayBinaryContains(String search, String... sortedValues) {
return Arrays.binarySearch(sortedValues, search) >= 0;
}
/** /**
* @param context android context * @param context android context
* @param date date to format * @param date date to format
@ -118,24 +125,22 @@ public class DateUtilities {
String month = DateUtils.getMonthString(date.getMonth() + String month = DateUtils.getMonthString(date.getMonth() +
Calendar.JANUARY, DateUtils.LENGTH_MEDIUM); Calendar.JANUARY, DateUtils.LENGTH_MEDIUM);
String value; String value;
String standardDate;
// united states, you are special // united states, you are special
if ("ko".equals(Locale.getDefault().getLanguage()) || Locale.US.equals(Locale.getDefault()) || "BZ".equals(Locale.getDefault().getCountry()) Locale locale = Locale.getDefault();
|| Locale.CANADA.equals(Locale.getDefault()) || "KE".equals(Locale.getDefault().getCountry()) if (arrayBinaryContains(locale.getLanguage(), "ja", "ko", "zh")
|| "MN".equals(Locale.getDefault().getCountry()) || "zh".equals(Locale.getDefault().getLanguage()) || arrayBinaryContains(locale.getCountry(), "BZ", "CA", "KE", "MN" ,"US"))
|| "ja".equals(Locale.getDefault().getLanguage())) value = "'#' d'%' yyyy";
value = "'#' d yyyy";
else else
value = "d '#' yyyy"; value = "d'%' '#' yyyy";
String standardDate = new SimpleDateFormat(value).format(date).replace("#", month); if (arrayBinaryContains(locale.getLanguage(), "ja", "zh")){
if (standardDate.length() < 5) standardDate = new SimpleDateFormat(value).format(date).replace("#", month).replace("%", "\u65E5"); //$NON-NLS-1$
return standardDate; }else if ("ko".equals(Locale.getDefault().getLanguage())){
if ("zh".equals(Locale.getDefault().getLanguage()) //$NON-NLS-1$ standardDate = new SimpleDateFormat(value).format(date).replace("#", month).replace("%", "\uC77C"); //$NON-NLS-1$
|| "ja".equals(Locale.getDefault().getLanguage())) //$NON-NLS-1$ }else{
return new StringBuilder(standardDate).insert(standardDate.length()-5, "\u65E5").toString(); //$NON-NLS-1$ standardDate = new SimpleDateFormat(value).format(date).replace("#", month).replace("%", "");
else if ("ko".equals(Locale.getDefault().getLanguage())) //$NON-NLS-1$ }
return new StringBuilder(standardDate).insert(standardDate.length()-5, "\uC77C").toString(); //$NON-NLS-1$ return standardDate;}
else
return standardDate; }
/** /**
* @param context android context * @param context android context
@ -147,11 +152,10 @@ public class DateUtilities {
String month = DateUtils.getMonthString(date.getMonth() + String month = DateUtils.getMonthString(date.getMonth() +
Calendar.JANUARY, DateUtils.LENGTH_MEDIUM); Calendar.JANUARY, DateUtils.LENGTH_MEDIUM);
String value; String value;
Locale locale = Locale.getDefault();
// united states, you are special // united states, you are special
if ("ko".equals(Locale.getDefault().getLanguage()) || Locale.US.equals(Locale.getDefault()) || "BZ".equals(Locale.getDefault().getCountry()) if (arrayBinaryContains(locale.getLanguage(), "ja", "ko", "zh")
|| Locale.CANADA.equals(Locale.getDefault()) || "KE".equals(Locale.getDefault().getCountry()) || arrayBinaryContains(locale.getCountry(), "BZ", "CA", "KE", "MN" ,"US"))
|| "MN".equals(Locale.getDefault().getCountry()) || "zh".equals(Locale.getDefault().getLanguage())
|| "ja".equals(Locale.getDefault().getLanguage()))
value = "'#' d"; value = "'#' d";
else else
value = "d '#'"; value = "d '#'";
@ -159,8 +163,7 @@ public class DateUtilities {
if (date.getYear() != (new Date()).getYear()) { if (date.getYear() != (new Date()).getYear()) {
value = value + "\nyyyy"; value = value + "\nyyyy";
} }
if ("zh".equals(Locale.getDefault().getLanguage()) //$NON-NLS-1$ if (arrayBinaryContains(locale.getLanguage(), "ja", "zh")) //$NON-NLS-1$
|| "ja".equals(Locale.getDefault().getLanguage())) //$NON-NLS-1$
return new SimpleDateFormat(value).format(date).replace("#", month) + "\u65E5"; //$NON-NLS-1$ return new SimpleDateFormat(value).format(date).replace("#", month) + "\u65E5"; //$NON-NLS-1$
else if ("ko".equals(Locale.getDefault().getLanguage())) //$NON-NLS-1$ else if ("ko".equals(Locale.getDefault().getLanguage())) //$NON-NLS-1$
return new SimpleDateFormat(value).format(date).replace("#", month) + "\uC77C"; //$NON-NLS-1$ return new SimpleDateFormat(value).format(date).replace("#", month) + "\uC77C"; //$NON-NLS-1$

Loading…
Cancel
Save