use of java.text.DateFormatSymbols in project h2database by h2database.
the class ToChar method getDateNames.
/**
* Get the date (month / weekday / ...) names.
*
* @param names the field
* @return the names
*/
static String[] getDateNames(int names) {
String[][] result = NAMES;
if (result == null) {
result = new String[5][];
DateFormatSymbols dfs = DateFormatSymbols.getInstance();
result[MONTHS] = dfs.getMonths();
String[] months = dfs.getShortMonths();
for (int i = 0; i < 12; i++) {
String month = months[i];
if (month.endsWith(".")) {
months[i] = month.substring(0, month.length() - 1);
}
}
result[SHORT_MONTHS] = months;
result[WEEKDAYS] = dfs.getWeekdays();
result[SHORT_WEEKDAYS] = dfs.getShortWeekdays();
result[AM_PM] = dfs.getAmPmStrings();
NAMES = result;
}
return result[names];
}
use of java.text.DateFormatSymbols in project h2database by h2database.
the class DateTimeFunctions method getMonthsAndWeeks.
/**
* Return names of month or weeks.
*
* @param field
* 0 for months, 1 for weekdays
* @return names of month or weeks
*/
public static String[] getMonthsAndWeeks(int field) {
String[][] result = MONTHS_AND_WEEKS;
if (result == null) {
result = new String[2][];
DateFormatSymbols dfs = DateFormatSymbols.getInstance(Locale.ENGLISH);
result[0] = dfs.getMonths();
result[1] = dfs.getWeekdays();
MONTHS_AND_WEEKS = result;
}
return result[field];
}
use of java.text.DateFormatSymbols in project box-android-sdk by box.
the class FastDateFormat method parsePattern.
// Parse the pattern
// -----------------------------------------------------------------------
/**
* <p>Returns a list of Rules given a pattern.</p>
*
* @return a <code>List</code> of Rule objects
* @throws IllegalArgumentException if pattern is invalid
*/
protected List parsePattern() {
DateFormatSymbols symbols = new DateFormatSymbols(mLocale);
List rules = new ArrayList();
String[] ERAs = symbols.getEras();
String[] months = symbols.getMonths();
String[] shortMonths = symbols.getShortMonths();
String[] weekdays = symbols.getWeekdays();
String[] shortWeekdays = symbols.getShortWeekdays();
String[] AmPmStrings = symbols.getAmPmStrings();
int length = mPattern.length();
int[] indexRef = new int[1];
for (int i = 0; i < length; i++) {
indexRef[0] = i;
String token = parseToken(mPattern, indexRef);
i = indexRef[0];
int tokenLen = token.length();
if (tokenLen == 0) {
break;
}
Rule rule;
char c = token.charAt(0);
switch(c) {
case // era designator (text)
'G':
rule = new TextField(Calendar.ERA, ERAs);
break;
case // year (number)
'y':
if (tokenLen >= 4) {
rule = selectNumberRule(Calendar.YEAR, tokenLen);
} else {
rule = TwoDigitYearField.INSTANCE;
}
break;
case // month in year (text and number)
'M':
if (tokenLen >= 4) {
rule = new TextField(Calendar.MONTH, months);
} else if (tokenLen == 3) {
rule = new TextField(Calendar.MONTH, shortMonths);
} else if (tokenLen == 2) {
rule = TwoDigitMonthField.INSTANCE;
} else {
rule = UnpaddedMonthField.INSTANCE;
}
break;
case // day in month (number)
'd':
rule = selectNumberRule(Calendar.DAY_OF_MONTH, tokenLen);
break;
case // hour in am/pm (number, 1..12)
'h':
rule = new TwelveHourField(selectNumberRule(Calendar.HOUR, tokenLen));
break;
case // hour in day (number, 0..23)
'H':
rule = selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen);
break;
case // minute in hour (number)
'm':
rule = selectNumberRule(Calendar.MINUTE, tokenLen);
break;
case // second in minute (number)
's':
rule = selectNumberRule(Calendar.SECOND, tokenLen);
break;
case // millisecond (number)
'S':
rule = selectNumberRule(Calendar.MILLISECOND, tokenLen);
break;
case // day in week (text)
'E':
rule = new TextField(Calendar.DAY_OF_WEEK, tokenLen < 4 ? shortWeekdays : weekdays);
break;
case // day in year (number)
'D':
rule = selectNumberRule(Calendar.DAY_OF_YEAR, tokenLen);
break;
case // day of week in month (number)
'F':
rule = selectNumberRule(Calendar.DAY_OF_WEEK_IN_MONTH, tokenLen);
break;
case // week in year (number)
'w':
rule = selectNumberRule(Calendar.WEEK_OF_YEAR, tokenLen);
break;
case // week in month (number)
'W':
rule = selectNumberRule(Calendar.WEEK_OF_MONTH, tokenLen);
break;
case // am/pm marker (text)
'a':
rule = new TextField(Calendar.AM_PM, AmPmStrings);
break;
case // hour in day (1..24)
'k':
rule = new TwentyFourHourField(selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen));
break;
case // hour in am/pm (0..11)
'K':
rule = selectNumberRule(Calendar.HOUR, tokenLen);
break;
case // time zone (text)
'z':
if (tokenLen >= 4) {
rule = new TimeZoneNameRule(mTimeZone, mTimeZoneForced, mLocale, TimeZone.LONG);
} else {
rule = new TimeZoneNameRule(mTimeZone, mTimeZoneForced, mLocale, TimeZone.SHORT);
}
break;
case // time zone (value)
'Z':
if (tokenLen == 1) {
rule = TimeZoneNumberRule.INSTANCE_NO_COLON;
} else {
rule = TimeZoneNumberRule.INSTANCE_COLON;
}
break;
case // literal text
'\'':
String sub = token.substring(1);
if (sub.length() == 1) {
rule = new CharacterLiteral(sub.charAt(0));
} else {
rule = new StringLiteral(sub);
}
break;
default:
throw new IllegalArgumentException("Illegal pattern component: " + token);
}
rules.add(rule);
}
return rules;
}
use of java.text.DateFormatSymbols in project teiid by teiid.
the class FunctionMethods method getDayNames.
static String[] getDayNames() {
if (dayNames == null) {
DateFormatSymbols dateFormatSymbols = DateFormatSymbols.getInstance(getSymbolLocale());
dayNames = Arrays.copyOfRange(dateFormatSymbols.getWeekdays(), 1, 8);
}
return dayNames;
}
use of java.text.DateFormatSymbols in project tutorials by eugenp.
the class DateFormatUnitTest method givenGregorianCalendar_whenCustomizedDateFormatSymbols_thenChangedDayNames.
@Test
public void givenGregorianCalendar_whenCustomizedDateFormatSymbols_thenChangedDayNames() {
GregorianCalendar gregorianCalendar = new GregorianCalendar(2018, 1, 1, 10, 15, 20);
Date date = gregorianCalendar.getTime();
Locale.setDefault(new Locale("pl", "PL"));
DateFormatSymbols dateFormatSymbols = new DateFormatSymbols();
dateFormatSymbols.setWeekdays(new String[] { "A", "B", "C", "D", "E", "F", "G", "H" });
SimpleDateFormat standardDateFormat = new SimpleDateFormat("EEEE-MMMM-yyyy HH:mm:ss:SSS");
SimpleDateFormat newDaysDateFormat = new SimpleDateFormat("EEEE-MMMM-yyyy HH:mm:ss:SSS", dateFormatSymbols);
Assert.assertEquals("czwartek-lutego-2018 10:15:20:000", standardDateFormat.format(date));
Assert.assertEquals("F-lutego-2018 10:15:20:000", newDaysDateFormat.format(date));
}
Aggregations