use of java.text.DateFormatSymbols in project processdash by dtuma.
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 tika by apache.
the class RFC822ParserTest method testTrickyDates.
@Test
public void testTrickyDates() throws Exception {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd", new DateFormatSymbols(Locale.US));
//make sure there are no mis-parses of e.g. 90 = year 90 A.D, not 1990
Date date1980 = df.parse("1980-01-01");
for (String dateString : new String[] { "Mon, 29 Jan 96 14:02 GMT", "7/20/95 1:12pm", "08/14/2000 12:48 AM", "06/24/2008, Tuesday, 11 AM", "11/14/08", "12/02/1996", "96/12/02" }) {
Date parsedDate = getDate(dateString);
if (parsedDate != null) {
assertTrue("date must be after 1980:" + dateString, parsedDate.getTime() > date1980.getTime());
}
}
//TODO: mime4j misparses these to pre 1980 dates
//"Wed, 27 Dec 95 11:20:40 EST",
//"26 Aug 00 11:14:52 EDT"
//
//We are still misparsing: 8/1/03 to a pre 1980 date
}
use of java.text.DateFormatSymbols in project Lucee by lucee.
the class MonthAsString method call.
protected static String call(double month, Locale locale, boolean _short) throws ExpressionException {
int m = (int) month;
if (m >= 1 && m <= 12) {
DateFormatSymbols dfs = new DateFormatSymbols(locale);
String[] months = _short ? dfs.getShortMonths() : dfs.getMonths();
return months[m - 1];
}
throw new ExpressionException("invalid month definition in function monthAsString, must be between 1 and 12 now [" + month + "]");
}
use of java.text.DateFormatSymbols in project instructure-android by instructure.
the class CalendarListViewFragment method setupActionbarSpinnerForMonth.
/**
* Helper method to configure actionbar button for calendar grid drop down
*/
private void setupActionbarSpinnerForMonth() {
mMonthContainer = LayoutInflater.from(getContext()).inflate(R.layout.actionbar_calendar_layout, null);
mToolbarContentWrapper.removeAllViews();
mToolbarContentWrapper.addView(mMonthContainer);
mDropDownIndicator = mMonthContainer.findViewById(R.id.indicator);
mDropDownIndicator.setImageDrawable(ColorKeeper.getColoredDrawable(getContext(), R.drawable.vd_expand, ThemePrefs.getPrimaryTextColor()));
mMonthText = mMonthContainer.findViewById(R.id.monthText);
if (mCalendarFragment.getCurrentMonth() != -1) {
// this is month - 1 because DateFormatSymbols uses 0 indexed months, and DateTime uses
// 1 indexed months.
mMonthText.setText(new DateFormatSymbols().getMonths()[mCalendarFragment.getCurrentMonth() - 1] + " " + mCalendarFragment.getCurrentYear());
}
mMonthContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
expandOrCollapseCalendar(mCalendarContainer, mCalendarContainer.getVisibility() == View.GONE);
}
});
mMonthText.setTextColor(ThemePrefs.getPrimaryTextColor());
}
use of java.text.DateFormatSymbols in project StreetComplete by westnordost.
the class Weekdays method getNames.
public static String[] getNames(Resources r) {
DateFormatSymbols symbols = DateFormatSymbols.getInstance();
String[] result = Arrays.copyOf(toIso8601Order(symbols.getWeekdays()), WEEKDAYS_VALUES);
result[PUBLIC_HOLIDAY] = r.getString(R.string.quest_openingHours_public_holidays);
return result;
}
Aggregations