List of usage examples for java.time.chrono IsoChronology INSTANCE
IsoChronology INSTANCE
To view the source code for java.time.chrono IsoChronology INSTANCE.
Click Source Link
From source file:Main.java
public static List<Person> createRoster() { List<Person> roster = new ArrayList<>(); roster.add(//from w w w .j av a 2 s .c om new Person("Fred", IsoChronology.INSTANCE.date(1980, 6, 20), Person.Sex.MALE, "fred@example.com")); roster.add(new Person("Jane", IsoChronology.INSTANCE.date(1990, 7, 15), Person.Sex.FEMALE, "jane@example.com")); roster.add(new Person("George", IsoChronology.INSTANCE.date(1991, 8, 13), Person.Sex.MALE, "george@example.com")); roster.add(new Person("Bob", IsoChronology.INSTANCE.date(2000, 9, 12), Person.Sex.MALE, "bob@example.com")); return roster; }
From source file:Main.java
public int getAge() { return birthday.until(IsoChronology.INSTANCE.dateNow()).getYears(); }
From source file:Main.java
/** * Converts a LocalDate (ISO) value to a ChronoLocalDate date using the * provided Chronology, and then formats the ChronoLocalDate to a String using * a DateTimeFormatter with a SHORT pattern based on the Chronology and the * current Locale.// ww w. j a v a 2 s . co m * * @param localDate * - the ISO date to convert and format. * @param chrono * - an optional Chronology. If null, then IsoChronology is used. */ public static String toString(LocalDate localDate, Chronology chrono) { if (localDate != null) { Locale locale = Locale.getDefault(Locale.Category.FORMAT); ChronoLocalDate cDate; if (chrono == null) { chrono = IsoChronology.INSTANCE; } try { cDate = chrono.date(localDate); } catch (DateTimeException ex) { System.err.println(ex); chrono = IsoChronology.INSTANCE; cDate = localDate; } String pattern = "M/d/yyyy GGGGG"; DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern(pattern); return dateFormatter.format(cDate); } else { return ""; } }
From source file:Main.java
/** * Parses a String to a ChronoLocalDate using a DateTimeFormatter with a short * pattern based on the current Locale and the provided Chronology, then * converts this to a LocalDate (ISO) value. * * @param text//ww w. j a v a 2 s. c om * - the input date text in the SHORT format expected for the * Chronology and the current Locale. * * @param chrono * - an optional Chronology. If null, then IsoChronology is used. */ public static LocalDate fromString(String text, Chronology chrono) { if (text != null && !text.isEmpty()) { Locale locale = Locale.getDefault(Locale.Category.FORMAT); if (chrono == null) { chrono = IsoChronology.INSTANCE; } String pattern = "M/d/yyyy GGGGG"; DateTimeFormatter df = new DateTimeFormatterBuilder().parseLenient().appendPattern(pattern) .toFormatter().withChronology(chrono).withDecimalStyle(DecimalStyle.of(locale)); TemporalAccessor temporal = df.parse(text); ChronoLocalDate cDate = chrono.date(temporal); return LocalDate.from(cDate); } return null; }
From source file:org.talend.dataquality.statistics.datetime.utils.PatternListGenerator.java
private static void getFormatByStyle(FormatStyle dateStyle, FormatStyle timeStyle, boolean isDateRequired, boolean isTimeRequired, Locale locale, boolean keepLongMonthAndSpecificChars) { String pattern = DateTimeFormatterBuilder.getLocalizedDateTimePattern(// isDateRequired ? dateStyle : null, isTimeRequired ? timeStyle : null, IsoChronology.INSTANCE, locale);// // ignore patterns with long month for additional languages if (!keepLongMonthAndSpecificChars && (pattern.contains("MMMM") || pattern.contains("MMM") || pattern.contains(" a") || pattern.contains("'"))) { return;// w w w . j a v a2 s . com } if (!pattern.contains("yy") && pattern.contains("y")) {// only one "y" to represent year part return; } if (!knownPatternList.contains(pattern)) { LocaledPattern lp = new LocaledPattern(pattern, locale, dateStyle.name(), isTimeRequired); knownLocaledPatternList.add(lp); knownPatternList.add(pattern); // update list of pattern strings without locale if (PRINT_DETAILED_RESULTS) { System.out.println(lp); } } else { if (pattern.contains("MMMM") || pattern.contains("MMM")) { if (PRINT_DETAILED_RESULTS) { System.out.print("!!!duplicated pattern with different locale!!! "); } LocaledPattern lp = new LocaledPattern(pattern, locale, dateStyle.name(), isTimeRequired); knownLocaledPatternList.add(lp); if (PRINT_DETAILED_RESULTS) { System.out.println(lp); } } } }
From source file:org.talend.dataquality.statistics.datetime.utils.PatternListGenerator.java
private static void generateDateFormats() throws IOException { int currentLocaledPatternSize = 0; knownLocaledPatternList.clear();//from w w w . java 2 s . c o m knownPatternList.clear(); // 1. Base Localized DateTimePatterns (java8 DateTimeFormatterBuilder) processBaseDateTimePatternsByLocales(); int basePatternCount = knownLocaledPatternList.size() - currentLocaledPatternSize; if (PRINT_DETAILED_RESULTS) { System.out.println("#basePatterns = " + basePatternCount + "\n"); } currentLocaledPatternSize = knownLocaledPatternList.size(); // 2. Other common DateTime patterns for (LocaledPattern lp : OTHER_COMMON_PATTERNS_NEED_COMBINATION) { addLocaledPattern(lp); for (Locale locale : primaryLocaleArray) { String patternShort = DateTimeFormatterBuilder.getLocalizedDateTimePattern(// null, FormatStyle.SHORT, IsoChronology.INSTANCE, locale);// LocaledPattern combinedShortLP = new LocaledPattern(lp.pattern + " " + patternShort, locale, FormatStyle.SHORT.name(), true); addLocaledPattern(combinedShortLP); String patternMedium = DateTimeFormatterBuilder.getLocalizedDateTimePattern(// null, FormatStyle.MEDIUM, IsoChronology.INSTANCE, locale);// LocaledPattern combinedMediumLP = new LocaledPattern(lp.pattern + " " + patternMedium, locale, FormatStyle.MEDIUM.name(), true); addLocaledPattern(combinedMediumLP); } } for (LocaledPattern lp : OTHER_COMMON_PATTERNS) { addLocaledPattern(lp); } // 3. ISO and RFC DateTimePatterns processISOAndRFCDateTimePatternList(); // knownPatternList.addAll(isoPatternList); int isoPatternCount = knownLocaledPatternList.size() - currentLocaledPatternSize; if (PRINT_DETAILED_RESULTS) { System.out.println("#DateTimePattern(ISO&RFC) = " + isoPatternCount + "\n"); } currentLocaledPatternSize = knownLocaledPatternList.size(); // 4. Additional Localized DateTimePatterns (java8 DateTimeFormatterBuilder) processAdditionalDateTimePatternsByLocales(); // knownPatternList.addAll(additionalPatternList); int additionalPatternCount = knownLocaledPatternList.size() - currentLocaledPatternSize; if (PRINT_DETAILED_RESULTS) { System.out.println("#additionalPatternList = " + additionalPatternCount + "\n"); } currentLocaledPatternSize = knownLocaledPatternList.size(); if (PRINT_DETAILED_RESULTS) { System.out.println("#Total = " + knownLocaledPatternList.size() + // " (#baseDatePatterns = " + basePatternCount + // ", #isoPatterns = " + isoPatternCount + // ", #additionalPatterns = " + additionalPatternCount + ")\n");// } // table header dateSampleFileTextBuilder.append("Sample\tPattern\tLocale\tFormatStyle\tIsWithTime\n"); RegexGenerator regexGenerator = new RegexGenerator(); for (LocaledPattern lp : knownLocaledPatternList) { datePatternFileTextBuilder.append(lp).append("\n"); String regex = regexGenerator.convertPatternToRegex(lp.pattern); dateRegexFileTextBuilder.append(lp.getPattern()).append("\t^").append(regex).append("$\n"); dateSampleFileTextBuilder .append(ZONED_DATE_TIME.format(DateTimeFormatter.ofPattern(lp.getPattern(), lp.getLocale()))) .append("\t").append(lp.getPattern())// .append("\t").append(lp.getLocale())// .append("\t").append(lp.getFormatStyle())// .append("\t").append(lp.isWithTime()).append("\n"); } // Date Formats String path = SystemDateTimePatternManager.class.getResource("DateFormats.txt").getFile().replace( "target" + File.separator + "classes", "src" + File.separator + "main" + File.separator + "resources"); IOUtils.write(datePatternFileTextBuilder.toString(), new FileOutputStream(new File(path))); // Date Regexes path = SystemDateTimePatternManager.class.getResource("DateRegexes.txt").getFile().replace( "target" + File.separator + "classes", "src" + File.separator + "main" + File.separator + "resources"); IOUtils.write(dateRegexFileTextBuilder.toString(), new FileOutputStream(new File(path))); // Date Samples path = SystemDateTimePatternManager.class.getResource("DateSampleTable.txt").getFile().replace( "target" + File.separator + "classes", "src" + File.separator + "test" + File.separator + "resources"); IOUtils.write(dateSampleFileTextBuilder.toString(), new FileOutputStream(new File(path))); // generate grouped Date Regexes FormatGroupGenerator.generateDateRegexGroups(); }