/* * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /** * @test * @bug 4052223 4089987 4469904 4326988 4486735 8008577 8045998 8140571 * 8216969 * @summary test DateFormat and SimpleDateFormat. * @library /java/text/testlib * @modules jdk.localedata * @run main/othervm -Djava.locale.providers=COMPAT,SPI DateFormatTest */ import java.util.*; import java.text.*; import static java.util.GregorianCalendar.*; public class DateFormatTest extends IntlTest { public static void main(String[] args) throws Exception { Locale reservedLocale = Locale.getDefault(); try { Locale.setDefault(Locale.US); new DateFormatTest().run(args); } finally { // restore the reserved locale Locale.setDefault(reservedLocale); } } // Test 4 digit year parsing with pattern "yy" @SuppressWarnings("deprecation") public void TestYearParsing() { String str = "7/Sep/2001"; Date exp = new Date(2001-1900, SEPTEMBER, 7); String pat = "d/MMM/yy"; SimpleDateFormat sdf = new SimpleDateFormat(pat, Locale.US); try { Date d = sdf.parse(str); logln(str + " parses with " + pat + " to " + d); if (d.getTime() != exp.getTime()) { errln("FAIL: Expected " + exp); } } catch (ParseException e) { errln(str + " parse fails with " + pat); } } // Test written by Wally Wedel and emailed to me. public void TestWallyWedel() { /* * Instantiate a TimeZone so we can get the ids. */ TimeZone tz = new SimpleTimeZone(7,""); /* * Computational variables. */ int offset, hours, minutes; /* * Instantiate a SimpleDateFormat set up to produce a full time zone name. */ SimpleDateFormat sdf = new SimpleDateFormat("zzzz"); /* * A String array for the time zone ids. */ String[] ids = TimeZone.getAvailableIDs(); /* * How many ids do we have? */ logln("Time Zone IDs size: " + ids.length); /* * Column headings (sort of) */ logln("Ordinal ID offset(h:m) name"); /* * Loop through the tzs. */ Date today = new Date(); Calendar cal = Calendar.getInstance(); for (int i = 0; i < ids.length; i++) { // logln(i + " " + ids[i]); TimeZone ttz = TimeZone.getTimeZone(ids[i]); // offset = ttz.getRawOffset(); cal.setTimeZone(ttz); cal.setTime(today); offset = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET); // logln(i + " " + ids[i] + " offset " + offset); char sign = '+'; if (offset < 0) { sign = '-'; offset = -offset; } hours = offset/3600000; minutes = (offset%3600000)/60000; String dstOffset = "" + sign + (hours < 10 ? "0" : "") + hours + ':' + (minutes < 10 ? "0" : "") + minutes; /* * Instantiate a date so we can display the time zone name. */ sdf.setTimeZone(ttz); /* * Format the output. */ StringBuffer tzS = new StringBuffer(); sdf.format(today,tzS, new FieldPosition(0)); String fmtOffset = tzS.toString(); String fmtDstOffset = null; if (fmtOffset.startsWith("GMT")) { fmtDstOffset = fmtOffset.substring(3); } /* * Show our result. */ boolean ok = fmtDstOffset == null || fmtDstOffset.equals(dstOffset); if (ok) { logln(i + " " + ids[i] + " " + dstOffset + " " + fmtOffset + (fmtDstOffset != null ? " ok" : " ?")); } else { errln(i + " " + ids[i] + " " + dstOffset + " " + fmtOffset + " *** FAIL ***"); } } } // Test equals public void TestEquals() { DateFormat fmtA = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.FULL); DateFormat fmtB = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.FULL); if (!fmtA.equals(fmtB)) { errln("FAIL"); } } // Check out some specific parsing problem @SuppressWarnings("deprecation") public void TestTwoDigitYearDSTParse() { SimpleDateFormat fullFmt = new SimpleDateFormat("EEE MMM dd HH:mm:ss.SSS zzz yyyy G"); //DateFormat fmt = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.FULL, // Locale.ENGLISH); SimpleDateFormat fmt = new SimpleDateFormat("dd-MMM-yy h:mm:ss 'o''clock' a z", Locale.ENGLISH); //Date date = new Date(2004-1900, Calendar.APRIL, 3, 2, 20, 47); //logln(fmt.format(date)); // This shows what the current locale format is //logln(((SimpleDateFormat)fmt).toPattern()); TimeZone save = TimeZone.getDefault(); TimeZone PST = TimeZone.getTimeZone("PST"); String s = "03-Apr-04 2:20:47 o'clock AM PST"; int hour = 2; try { TimeZone.setDefault(PST); Date d = fmt.parse(s); logln(s + " P> " + fullFmt.format(d)); if (d.getHours() != hour) { errln("FAIL: Should parse to hour " + hour); } } catch (ParseException e) { errln("FAIL: " + e.getMessage()); } finally { TimeZone.setDefault(save); } } static String escape(String s) { StringBuilder buf = new StringBuilder(); for (int i=0; i> 12)); buf.append(Integer.toHexString((c & 0x0F00) >> 8)); buf.append(Integer.toHexString((c & 0x00F0) >> 4)); buf.append(Integer.toHexString(c & 0x000F)); } } return buf.toString(); } // Test field position return values static String fieldNames[] = { "ERA_FIELD", "YEAR_FIELD", "MONTH_FIELD", "WEEK_OF_YEAR_FIELD", "WEEK_OF_MONTH_FIELD", "DATE_FIELD", "DAY_OF_YEAR_FIELD", "DAY_OF_WEEK_FIELD", "DAY_OF_WEEK_IN_MONTH_FIELD", "AM_PM_FIELD", "HOUR0_FIELD", "HOUR1_FIELD", "HOUR_OF_DAY0_FIELD", "HOUR_OF_DAY1_FIELD", "MINUTE_FIELD", "SECOND_FIELD", "MILLISECOND_FIELD", "TIMEZONE_FIELD", }; static int fieldIDs[] = { DateFormat.ERA_FIELD, DateFormat.YEAR_FIELD, DateFormat.MONTH_FIELD, DateFormat.WEEK_OF_YEAR_FIELD, DateFormat.WEEK_OF_MONTH_FIELD, DateFormat.DATE_FIELD, DateFormat.DAY_OF_YEAR_FIELD, DateFormat.DAY_OF_WEEK_FIELD, DateFormat.DAY_OF_WEEK_IN_MONTH_FIELD, DateFormat.AM_PM_FIELD, DateFormat.HOUR0_FIELD, DateFormat.HOUR1_FIELD, DateFormat.HOUR_OF_DAY0_FIELD, DateFormat.HOUR_OF_DAY1_FIELD, DateFormat.MINUTE_FIELD, DateFormat.SECOND_FIELD, DateFormat.MILLISECOND_FIELD, DateFormat.TIMEZONE_FIELD, }; /** * Bug 4089987 */ public void TestFieldPosition() { DateFormat[] dateFormats = { DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL, Locale.US), DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL,Locale.FRANCE), new SimpleDateFormat("G, y, M, d, k, H, m, s, S, E, D, F, w, W, a, h, K, z"), new SimpleDateFormat("G, yy, M, d, k, H, m, s, S, E, D, F, w, W, a, h, K, z"), new SimpleDateFormat( "GGGG, yyyy, MMMM, dddd, kkkk, HHHH, mmmm, ssss, " + "SSSS, EEEE, DDDD, " + "FFFF, wwww, WWWW, aaaa, hhhh, KKKK, zzzz") }; String[] expected = { "", "1997", "August", "", "", "13", "", "Wednesday", "", "PM", "", "2", "", "", "34", "12", "", "PDT", "", "1997", "ao\u00FBt", "", "", "13", "", "mercredi", "", "", "", "", "14", "", "34", "", "", "PDT" /*"GMT-07:00"*/, "AD", "1997", "8", "33", "3", "13", "225", "Wed", "2", "PM", "2", "2", "14", "14", "34", "12", "513", "PDT", "AD", "97", "8", "33", "3", "13", "225", "Wed", "2", "PM", "2", "2", "14", "14", "34", "12", "513", "PDT", "AD", "1997", "August", "0033", "0003", "0013", "0225", "Wednesday", "0002", "PM", "0002", "0002", "0014", "0014", "0034", "0012", "0513", "Pacific Daylight Time", }; Date someDate = new Date(871508052513L); TimeZone PST = TimeZone.getTimeZone("PST"); for (int j = 0, exp = 0; j < dateFormats.length; ++j) { DateFormat df = dateFormats[j]; if (!(df instanceof SimpleDateFormat)) { continue; } df.setTimeZone(PST); logln(" Pattern = " + ((SimpleDateFormat)df).toPattern()); logln(" Result = " + df.format(someDate)); for (int i = 0; i < fieldIDs.length; ++i) { String field = getFieldText(df, fieldIDs[i], someDate); if (!field.equals(expected[exp])) { errln("FAIL: field #" + i + " " + fieldNames[i] + " = \"" + escape(field) + "\", expected \"" + escape(expected[exp]) + "\""); } ++exp; } } } // get the string value for the given field for the given date static String getFieldText(DateFormat df, int field, Date date) { StringBuffer buffer = new StringBuffer(); FieldPosition pos = new FieldPosition(field); df.format(date, buffer, pos); return buffer.toString().substring(pos.getBeginIndex(), pos.getEndIndex()); } // Test parsing of partial strings @SuppressWarnings("deprecation") public void TestPartialParse994() { SimpleDateFormat f = new SimpleDateFormat(); Calendar cal = new GregorianCalendar(2014 - 80, JANUARY, 1); f.set2DigitYearStart(cal.getTime()); tryPat994(f, "yy/MM/dd HH:mm:ss", "97/01/17 10:11:42", new Date(97, 1-1, 17, 10, 11, 42)); tryPat994(f, "yy/MM/dd HH:mm:ss", "97/01/17 10:", null); tryPat994(f, "yy/MM/dd HH:mm:ss", "97/01/17 10", null); tryPat994(f, "yy/MM/dd HH:mm:ss", "97/01/17 ", null); tryPat994(f, "yy/MM/dd HH:mm:ss", "97/01/17", null); } void tryPat994(SimpleDateFormat format, String pat, String str, Date expected) { logln("Pattern \"" + pat + "\" String \"" + str + "\""); try { format.applyPattern(pat); Date date = format.parse(str); String f = format.format(date); logln(" parse(" + str + ") -> " + date.toString()); logln(" format -> " + f); if (expected == null || !date.equals(expected)) { errln("FAIL: Expected " + expected); } if (!f.equals(str)) { errln("FAIL: Expected " + str); } } catch(ParseException e) { logln("ParseException: " + e.getMessage()); if (expected != null) { errln("FAIL: Expected " + expected); } } catch(Exception e) { errln("*** Exception:"); e.printStackTrace(); } } // Test pattern with runs things together public void TestRunTogetherPattern985() { String format = "yyyyMMddHHmmssSSS"; String now, then; SimpleDateFormat formatter = new SimpleDateFormat(format); Date date1 = new Date(); now = formatter.format(date1); logln(now); ParsePosition pos = new ParsePosition(0); Date date2 = formatter.parse(now, pos); if (date2 == null) { then = "Parse stopped at " + pos.getIndex(); } else { then = formatter.format(date2); } logln(then); if (!date2.equals(date1)) { errln("FAIL"); } } // Test patterns which run numbers together @SuppressWarnings("deprecation") public void TestRunTogetherPattern917() { SimpleDateFormat fmt; String myDate; fmt = new SimpleDateFormat( "yyyy/MM/dd" ); myDate = "1997/02/03"; _testIt917( fmt, myDate, new Date(97, 2-1, 3) ); fmt = new SimpleDateFormat( "yyyyMMdd" ); myDate = "19970304"; _testIt917( fmt, myDate, new Date(97, 3-1, 4) ); } void _testIt917( SimpleDateFormat fmt, String str, Date expected ) { logln( "pattern=" + fmt.toPattern() + " string=" + str ); Object o; try { o = fmt.parseObject( str ); } catch( ParseException e ) { e.printStackTrace(); return; } logln( "Parsed object: " + o ); if (!o.equals(expected)) { errln("FAIL: Expected " + expected); } String formatted = fmt.format( o ); logln( "Formatted string: " + formatted ); if (!formatted.equals(str)) { errln("FAIL: Expected " + str); } } // Test Czech month formatting -- this can cause a problem because the June and // July month names share a common prefix. @SuppressWarnings("deprecation") public void TestCzechMonths459() { // Use Czech, which has month names with shared prefixes for June and July DateFormat fmt = DateFormat.getDateInstance(DateFormat.FULL, new Locale("cs", "", "")); //((SimpleDateFormat)fmt).applyPattern("MMMM d yyyy"); logln("Pattern " + ((SimpleDateFormat)fmt).toPattern()); Date june = new Date(97, Calendar.JUNE, 15); Date july = new Date(97, Calendar.JULY, 15); String juneStr = fmt.format(june); String julyStr = fmt.format(july); try { logln("format(June 15 1997) = " + juneStr); Date d = fmt.parse(juneStr); String s = fmt.format(d); int month = d.getMonth(); logln(" -> parse -> " + s + " (month = " + month + ")"); if (month != JUNE) { errln("FAIL: Month should be June"); } logln("format(July 15 1997) = " + julyStr); d = fmt.parse(julyStr); s = fmt.format(d); month = d.getMonth(); logln(" -> parse -> " + s + " (month = " + month + ")"); if (month != JULY) { errln("FAIL: Month should be July"); } } catch (ParseException e) { errln("Exception: " + e); } } // Test big D (day of year) versus little d (day of month) @SuppressWarnings("deprecation") public void TestLetterDPattern212() { String dateString = "1995-040.05:01:29"; String bigD = "yyyy-DDD.hh:mm:ss"; String littleD = "yyyy-ddd.hh:mm:ss"; Date expLittleD = new Date(95, 0, 1, 5, 1, 29); Date expBigD = new Date(expLittleD.getTime() + 39*24*3600000L); // 39 days expLittleD = expBigD; // Expect the same, with default lenient parsing logln( "dateString= " + dateString ); SimpleDateFormat formatter = new SimpleDateFormat(bigD); ParsePosition pos = new ParsePosition(0); Date myDate = formatter.parse( dateString, pos ); logln("Using " + bigD + " -> " + myDate); if (myDate.getTime() != expBigD.getTime()) { errln("FAIL: Expected " + expBigD + " got " + myDate); } formatter = new SimpleDateFormat(littleD); pos = new ParsePosition(0); myDate = formatter.parse( dateString, pos ); logln("Using " + littleD + " -> " + myDate); if (myDate.getTime() != expLittleD.getTime()) { errln("FAIL: Expected " + expLittleD + " got " + myDate); } } // Test the 'G' day of year pattern @SuppressWarnings("deprecation") public void TestDayOfYearPattern195() { Date today = new Date(); Date expected = new Date(today.getYear(), today.getMonth(), today.getDate()); logln("Test Date: " + today); SimpleDateFormat sdf = (SimpleDateFormat)SimpleDateFormat.getDateInstance(); tryPattern(sdf, today, null, expected); tryPattern(sdf, today, "G yyyy DDD", expected); } void tryPattern(SimpleDateFormat sdf, Date d, String pattern, Date expected) { if (pattern != null) { sdf.applyPattern(pattern); } logln("pattern: " + sdf.toPattern()); String formatResult = sdf.format(d); logln(" format -> " + formatResult); try { Date d2 = sdf.parse(formatResult); logln(" parse(" + formatResult + ") -> " + d2); if (d2.getTime() != expected.getTime()) { errln("FAIL: Expected " + expected); } String format2 = sdf.format(d2); logln(" format -> " + format2); if (!formatResult.equals(format2)) { errln("FAIL: Round trip drift"); } } catch(Exception e) { errln("Error: " + e.getMessage()); } } // Test a pattern with single quotes @SuppressWarnings("deprecation") public void TestQuotePattern161() { // This pattern used to end in " zzz" but that makes this test zone-dependent SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy 'at' hh:mm:ss a zzz"); Date currentTime_1 = new Date(97, Calendar.AUGUST, 13, 10, 42, 28); String dateString = formatter.format(currentTime_1); String exp = "08/13/1997 at 10:42:28 AM "; logln("format(" + currentTime_1 + ") = " + dateString); if (!dateString.regionMatches(0, exp, 0, exp.length())) { errln("FAIL: Expected " + exp); } } // Test the parsing of bad input strings /** Demonstrates a number of bugs in DateFormat.parse(String) where * either StringIndexOutOfBoundsException is thrown or null is * returned instead of ParseException. To reproduce, run this program * and notice all the "SHOULD NOT HAPPEN" errors. Note also that the * 1 line that should be correct is off by 100 years. (In this day * and age, no one would assume that 1/1/00 is Jan 1 1900.) **/ public void TestBadInput135() { int looks[] = { DateFormat.SHORT, DateFormat.MEDIUM, DateFormat.LONG, DateFormat.FULL }; String strings[] = { "Mar 15", "Mar 15 1997", "asdf", "3/1/97 1:23:", "3/1/00 1:23:45 AM" }; DateFormat full = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG); String expected = "March 1, 2000 1:23:45 AM "; for ( int i = 0; i < strings.length; ++i ){ String text = strings[i]; for ( int j = 0; j < looks.length; ++j ){ int dateLook = looks[j]; for ( int k = 0; k < looks.length; ++k ){ int timeLook = looks[k]; DateFormat df = DateFormat.getDateTimeInstance(dateLook, timeLook); String prefix = text + ", " + dateLook + "/" + timeLook + ": "; try { Date when = df.parse(text); if ( when == null ){ errln(prefix + "SHOULD NOT HAPPEN: parse returned null."); continue; } String format = full.format(when); logln(prefix + "OK: " + format); // Only match the start -- not the zone, which could vary if (!format.regionMatches(0, expected, 0, expected.length())) { errln("FAIL: Expected " + expected); } } catch ( ParseException e ){ //errln(prefix + e); // This is expected. } catch ( StringIndexOutOfBoundsException e ){ errln(prefix + "SHOULD NOT HAPPEN: " + e); } } } } } final private static String parseFormats[] = { "MMMM d, yyyy", // january 1, 1970 or jan 1, 1970 "MMMM d yyyy", // january 1 1970 or jan 1 1970 "M/d/yy", // 1/1/70 "d MMMM, yyyy", // 1 january, 1970 or 1 jan, 1970 "d MMMM yyyy", // 1 january 1970 or 1 jan 1970 "d MMMM", // 1 january or 1 jan "MMMM d", // january 1 or jan 1 "yyyy", // 1970 "h:mm a MMMM d, yyyy" // Date and Time }; final private static String inputStrings[] = { "bogus string", null, null, null, null, null, null, null, null, null, "April 1, 1997", "April 1, 1997", null, null, null, null, null, "April 1", null, null, "Jan 1, 1970", "January 1, 1970", null, null, null, null, null, "January 1", null, null, "Jan 1 2037", null, "January 1 2037", null, null, null, null, "January 1", null, null, "1/1/70", null, null, "1/1/70", null, null, null, null, "0001", null, "5 May 1997", null, null, null, null, "5 May 1997", "5 May", null, "0005", null, "16 May", null, null, null, null, null, "16 May", null, "0016", null, "April 30", null, null, null, null, null, null, "April 30", null, null, "1998", null, null, null, null, null, null, null, "1998", null, "1", null, null, null, null, null, null, null, "0001", null, // Bug620 "3:00 pm Jan 1, 1997", null, null, null, null, null, null, null, "0003", "3:00 PM January 1, 1997", }; // More testing of the parsing of bad input @SuppressWarnings("UnusedAssignment") public void TestBadInput135a() { SimpleDateFormat dateParse = new SimpleDateFormat(); String s; Date date; int PFLENGTH = parseFormats.length; dateParse.applyPattern("d MMMM, yyyy"); dateParse.setTimeZone(TimeZone.getDefault()); s = "not parseable"; logln("Trying to parse \"" + s + "\" with " + dateParse.toPattern()); try { date = dateParse.parse(s); errln("FAIL: Expected exception during parse"); } catch (Exception ex) { logln("Exception during parse: " + ex); // This is expected } for (int i=0; i " + d.toString()); if (d.getTime() != expected.getTime()) { errln("FAIL: Expected " + expected); } } catch (ParseException e) { errln("FAIL: Got exception"); } } // Test behavior of DateFormat with applied time zone public void TestDateFormatZone061() { Date date; DateFormat formatter; // 25-Mar-97 00:00:00 GMT date = new Date( 859248000000L ); logln( "Date 1997/3/25 00:00 GMT: " + date ); formatter = new SimpleDateFormat("dd-MMM-yyyyy HH:mm", Locale.UK); formatter.setTimeZone( TimeZone.getTimeZone( "GMT" ) ); String temp = formatter.format( date ); logln( "Formatted in GMT to: " + temp ); /* Parse date string */ try { Date tempDate = formatter.parse( temp ); logln( "Parsed to: " + tempDate ); if (tempDate.getTime() != date.getTime()) { errln("FAIL: Expected " + date); } } catch( Throwable t ) { errln( "Date Formatter throws: " + t.toString() ); } } // Make sure DateFormat uses the correct zone. public void TestDateFormatZone146() { TimeZone saveDefault = TimeZone.getDefault(); try { TimeZone thedefault = TimeZone.getTimeZone("GMT"); TimeZone.setDefault(thedefault); // java.util.Locale.setDefault(new java.util.Locale("ar", "", "")); // check to be sure... its GMT all right TimeZone testdefault = TimeZone.getDefault(); String testtimezone = testdefault.getID(); if (testtimezone.equals("GMT")) { logln("Test timezone = " + testtimezone); } else { errln("Test timezone should be GMT, not " + testtimezone); } // now try to use the default GMT time zone GregorianCalendar greenwichcalendar = new GregorianCalendar(1997, 3, 4, 23, 0); //*****************************greenwichcalendar.setTimeZone(TimeZone.getDefault()); //greenwichcalendar.set(1997, 3, 4, 23, 0); // try anything to set hour to 23:00 !!! greenwichcalendar.set(Calendar.HOUR_OF_DAY, 23); // get time Date greenwichdate = greenwichcalendar.getTime(); // format every way String[] DATA = { "simple format: ", "04/04/97 23:00 GMT", "MM/dd/yy HH:mm z", "full format: ", "Friday, April 4, 1997 11:00:00 o'clock PM GMT", "EEEE, MMMM d, yyyy h:mm:ss 'o''clock' a z", "long format: ", "April 4, 1997 11:00:00 PM GMT", "MMMM d, yyyy h:mm:ss a z", "default format: ", "04-Apr-97 11:00:00 PM", "dd-MMM-yy h:mm:ss a", "short format: ", "4/4/97 11:00 PM", "M/d/yy h:mm a", }; for (int i=0; i4 y's produces just "2001" until 1.3.1. This // was fixed in 1.4. String expected = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "\u6642\u9593:\u6642\u9593:\u6642\u9593:\u6642\u9593:\u6642\u9593:" + "\u6642\u9593:\u6642\u9593:\u6642\u9593:\u6642\u9593:\u6642\u9593:" + "\u6642\u9593:\u6642\u9593:\u6642\u9593:\u6642\u9593:\u6642\u9593:" + "\u6642\u9593:\u6642\u9593:\u6642\u9593:\u6642\u9593:\u6642\u9593:" + "\u6642\u9593:\u6642\u9593:\u6642\u9593:\u6642\u9593:\u6642\u9593:" + "00000000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000002001\u5e74"; SimpleDateFormat sdf = new SimpleDateFormat(pat); String s = sdf.format(new Date(2001-1900, Calendar.JANUARY, 1)); if (!expected.equals(s)) { errln("wrong format result: expected="+expected+", got="+s); } Date longday = sdf.parse(s); GregorianCalendar cal = new GregorianCalendar(); cal.setTime(longday); if (cal.get(YEAR) != 2001) { errln("wrong parse result: expected=2001, got=" + cal.get(YEAR)); } } catch (Exception e) { throw e; } finally { // Restore the initial time zone TimeZone.setDefault(initialTimeZone); } } public void Test8216969() throws Exception { Locale locale = new Locale("ru"); String format = "\u0434\u0435\u043a"; String standalone = "\u0434\u0435\u043a."; // Check that format form is used so that the dot is parsed correctly. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMM.yyyy", locale); System.out.println(simpleDateFormat.parse("28 " + format + ".2018")); // Check that standalone form is used. simpleDateFormat = new SimpleDateFormat("MMM", locale); System.out.println(simpleDateFormat.parse(standalone)); } }