8339644: Improve parsing of Day/Month in tzdata rules
Reviewed-by: jlu, coffeys
This commit is contained in:
parent
a9bb04331d
commit
86a2f9c7dc
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -364,33 +364,35 @@ class TzdbZoneRulesProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Month parseMonth(String mon) {
|
Month parseMonth(String mon) {
|
||||||
switch (mon) {
|
int len = mon.length();
|
||||||
case "Jan": return Month.JANUARY;
|
|
||||||
case "Feb": return Month.FEBRUARY;
|
if (mon.regionMatches(true, 0, "January", 0, len)) return Month.JANUARY;
|
||||||
case "Mar": return Month.MARCH;
|
if (mon.regionMatches(true, 0, "February", 0, len)) return Month.FEBRUARY;
|
||||||
case "Apr": return Month.APRIL;
|
if (mon.regionMatches(true, 0, "March", 0, len)) return Month.MARCH;
|
||||||
case "May": return Month.MAY;
|
if (mon.regionMatches(true, 0, "April", 0, len)) return Month.APRIL;
|
||||||
case "Jun": return Month.JUNE;
|
if (mon.regionMatches(true, 0, "May", 0, len)) return Month.MAY;
|
||||||
case "Jul": return Month.JULY;
|
if (mon.regionMatches(true, 0, "June", 0, len)) return Month.JUNE;
|
||||||
case "Aug": return Month.AUGUST;
|
if (mon.regionMatches(true, 0, "July", 0, len)) return Month.JULY;
|
||||||
case "Sep": return Month.SEPTEMBER;
|
if (mon.regionMatches(true, 0, "August", 0, len)) return Month.AUGUST;
|
||||||
case "Oct": return Month.OCTOBER;
|
if (mon.regionMatches(true, 0, "September", 0, len)) return Month.SEPTEMBER;
|
||||||
case "Nov": return Month.NOVEMBER;
|
if (mon.regionMatches(true, 0, "October", 0, len)) return Month.OCTOBER;
|
||||||
case "Dec": return Month.DECEMBER;
|
if (mon.regionMatches(true, 0, "November", 0, len)) return Month.NOVEMBER;
|
||||||
}
|
if (mon.regionMatches(true, 0, "December", 0, len)) return Month.DECEMBER;
|
||||||
|
|
||||||
throw new IllegalArgumentException("Unknown month: " + mon);
|
throw new IllegalArgumentException("Unknown month: " + mon);
|
||||||
}
|
}
|
||||||
|
|
||||||
DayOfWeek parseDayOfWeek(String dow) {
|
DayOfWeek parseDayOfWeek(String dow) {
|
||||||
switch (dow) {
|
int len = dow.length();
|
||||||
case "Mon": return DayOfWeek.MONDAY;
|
|
||||||
case "Tue": return DayOfWeek.TUESDAY;
|
if (dow.regionMatches(true, 0, "Monday", 0, len)) return DayOfWeek.MONDAY;
|
||||||
case "Wed": return DayOfWeek.WEDNESDAY;
|
if (dow.regionMatches(true, 0, "Tuesday", 0, len)) return DayOfWeek.TUESDAY;
|
||||||
case "Thu": return DayOfWeek.THURSDAY;
|
if (dow.regionMatches(true, 0, "Wednesday", 0, len)) return DayOfWeek.WEDNESDAY;
|
||||||
case "Fri": return DayOfWeek.FRIDAY;
|
if (dow.regionMatches(true, 0, "Thursday", 0, len)) return DayOfWeek.THURSDAY;
|
||||||
case "Sat": return DayOfWeek.SATURDAY;
|
if (dow.regionMatches(true, 0, "Friday", 0, len)) return DayOfWeek.FRIDAY;
|
||||||
case "Sun": return DayOfWeek.SUNDAY;
|
if (dow.regionMatches(true, 0, "Saturday", 0, len)) return DayOfWeek.SATURDAY;
|
||||||
}
|
if (dow.regionMatches(true, 0, "Sunday", 0, len)) return DayOfWeek.SUNDAY;
|
||||||
|
|
||||||
throw new IllegalArgumentException("Unknown day-of-week: " + dow);
|
throw new IllegalArgumentException("Unknown day-of-week: " + dow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -21,11 +21,6 @@
|
|||||||
* questions.
|
* questions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Month enum handles month related manipulation.
|
* Month enum handles month related manipulation.
|
||||||
*
|
*
|
||||||
@ -47,15 +42,6 @@ enum Month {
|
|||||||
|
|
||||||
private final String abbr;
|
private final String abbr;
|
||||||
|
|
||||||
private static final Map<String,Month> abbreviations
|
|
||||||
= new HashMap<String,Month>(12);
|
|
||||||
|
|
||||||
static {
|
|
||||||
for (Month m : Month.values()) {
|
|
||||||
abbreviations.put(m.abbr, m);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Month(String abbr) {
|
private Month(String abbr) {
|
||||||
this.abbr = abbr;
|
this.abbr = abbr;
|
||||||
}
|
}
|
||||||
@ -70,11 +56,22 @@ enum Month {
|
|||||||
* @return the Month value
|
* @return the Month value
|
||||||
*/
|
*/
|
||||||
static Month parse(String name) {
|
static Month parse(String name) {
|
||||||
Month m = abbreviations.get(name);
|
int len = name.length();
|
||||||
if (m != null) {
|
|
||||||
return m;
|
if (name.regionMatches(true, 0, "January", 0, len)) return Month.JANUARY;
|
||||||
}
|
if (name.regionMatches(true, 0, "February", 0, len)) return Month.FEBRUARY;
|
||||||
return null;
|
if (name.regionMatches(true, 0, "March", 0, len)) return Month.MARCH;
|
||||||
|
if (name.regionMatches(true, 0, "April", 0, len)) return Month.APRIL;
|
||||||
|
if (name.regionMatches(true, 0, "May", 0, len)) return Month.MAY;
|
||||||
|
if (name.regionMatches(true, 0, "June", 0, len)) return Month.JUNE;
|
||||||
|
if (name.regionMatches(true, 0, "July", 0, len)) return Month.JULY;
|
||||||
|
if (name.regionMatches(true, 0, "August", 0, len)) return Month.AUGUST;
|
||||||
|
if (name.regionMatches(true, 0, "September", 0, len)) return Month.SEPTEMBER;
|
||||||
|
if (name.regionMatches(true, 0, "October", 0, len)) return Month.OCTOBER;
|
||||||
|
if (name.regionMatches(true, 0, "November", 0, len)) return Month.NOVEMBER;
|
||||||
|
if (name.regionMatches(true, 0, "December", 0, len)) return Month.DECEMBER;
|
||||||
|
|
||||||
|
throw new IllegalArgumentException("Unknown month: " + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -21,11 +21,6 @@
|
|||||||
* questions.
|
* questions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RuleDay class represents the value of the "ON" field. The day of
|
* RuleDay class represents the value of the "ON" field. The day of
|
||||||
* week values start from 1 following the {@link java.util.Calendar}
|
* week values start from 1 following the {@link java.util.Calendar}
|
||||||
@ -34,13 +29,6 @@ import java.util.Map;
|
|||||||
* @since 1.4
|
* @since 1.4
|
||||||
*/
|
*/
|
||||||
class RuleDay {
|
class RuleDay {
|
||||||
private static final Map<String,DayOfWeek> abbreviations = new HashMap<String,DayOfWeek>(7);
|
|
||||||
static {
|
|
||||||
for (DayOfWeek day : DayOfWeek.values()) {
|
|
||||||
abbreviations.put(day.getAbbr(), day);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String dayName = null;
|
private String dayName = null;
|
||||||
private DayOfWeek dow;
|
private DayOfWeek dow;
|
||||||
private boolean lastOne = false;
|
private boolean lastOne = false;
|
||||||
@ -166,13 +154,23 @@ class RuleDay {
|
|||||||
return sign + toString(d);
|
return sign + toString(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DayOfWeek getDOW(String abbr) {
|
private static DayOfWeek getDOW(String name) {
|
||||||
return abbreviations.get(abbr);
|
int len = name.length();
|
||||||
|
|
||||||
|
if (name.regionMatches(true, 0, "Monday", 0, len)) return DayOfWeek.MONDAY;
|
||||||
|
if (name.regionMatches(true, 0, "Tuesday", 0, len)) return DayOfWeek.TUESDAY;
|
||||||
|
if (name.regionMatches(true, 0, "Wednesday", 0, len)) return DayOfWeek.WEDNESDAY;
|
||||||
|
if (name.regionMatches(true, 0, "Thursday", 0, len)) return DayOfWeek.THURSDAY;
|
||||||
|
if (name.regionMatches(true, 0, "Friday", 0, len)) return DayOfWeek.FRIDAY;
|
||||||
|
if (name.regionMatches(true, 0, "Saturday", 0, len)) return DayOfWeek.SATURDAY;
|
||||||
|
if (name.regionMatches(true, 0, "Sunday", 0, len)) return DayOfWeek.SUNDAY;
|
||||||
|
|
||||||
|
throw new IllegalArgumentException("Unknown day-of-week: " + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the specified day of week value to the day-of-week
|
* Converts the specified day of week value to the day-of-week
|
||||||
* name defined in {@link java.util.Calenda}.
|
* name defined in {@link java.util.Calendar}.
|
||||||
* @param dow 1-based day of week value
|
* @param dow 1-based day of week value
|
||||||
* @return the Calendar day of week name with "Calendar." prefix.
|
* @return the Calendar day of week name with "Calendar." prefix.
|
||||||
* @throws IllegalArgumentException if the specified dow value is out of range.
|
* @throws IllegalArgumentException if the specified dow value is out of range.
|
||||||
|
Loading…
Reference in New Issue
Block a user