List of usage examples for org.joda.time.format ISODateTimeFormat date
public static DateTimeFormatter date()
From source file:org.filteredpush.qc.date.DateUtils.java
License:Apache License
/** * Extract a single joda date from an event date. * /*from w w w. ja v a2 s.com*/ * @param eventDate an event date from which to try to extract a DateMidnight * @return a DateMidnight or null if a date cannot be extracted */ public static DateMidnight extractDate(String eventDate) { DateMidnight result = null; DateTimeParser[] parsers = { DateTimeFormat.forPattern("yyyy-MM").getParser(), DateTimeFormat.forPattern("yyyy").getParser(), DateTimeFormat.forPattern("yyyy-MM-dd/yyyy-MM-dd").getParser(), ISODateTimeFormat.dateOptionalTimeParser().getParser(), ISODateTimeFormat.date().getParser() }; DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers).toFormatter(); try { result = DateMidnight.parse(eventDate, formatter); logger.debug(result); } catch (Exception e) { // not a date logger.error(e.getMessage()); } return result; }
From source file:org.finra.datagenerator.engine.scxml.tags.boundary.BoundaryDate.java
License:Apache License
/** * Takes a date, and retrieves the next business day * * @param dateString the date/* www .j a v a 2 s . co m*/ * @param onlyBusinessDays only business days * @return a string containing the next business day */ public String getNextDay(String dateString, boolean onlyBusinessDays) { DateTimeFormatter parser = ISODateTimeFormat.date(); DateTime date = parser.parseDateTime(dateString).plusDays(1); Calendar cal = Calendar.getInstance(); cal.setTime(date.toDate()); if (onlyBusinessDays) { if (cal.get(Calendar.DAY_OF_WEEK) == 1 || cal.get(Calendar.DAY_OF_WEEK) == 7 || isHoliday(date.toString().substring(0, 10))) { return getNextDay(date.toString().substring(0, 10), true); } else { return parser.print(date); } } else { return parser.print(date); } }
From source file:org.finra.datagenerator.engine.scxml.tags.boundary.BoundaryDate.java
License:Apache License
/** * Takes a date, and returns the previous business day * * @param dateString the date/*from w ww .ja v a 2 s. c o m*/ * @param onlyBusinessDays only business days * @return the previous business day */ public String getPreviousDay(String dateString, boolean onlyBusinessDays) { DateTimeFormatter parser = ISODateTimeFormat.date(); DateTime date = parser.parseDateTime(dateString).minusDays(1); Calendar cal = Calendar.getInstance(); cal.setTime(date.toDate()); if (onlyBusinessDays) { if (cal.get(Calendar.DAY_OF_WEEK) == 1 || cal.get(Calendar.DAY_OF_WEEK) == 7 || isHoliday(date.toString().substring(0, 10))) { return getPreviousDay(date.toString().substring(0, 10), true); } else { return parser.print(date); } } else { return parser.print(date); } }
From source file:org.finra.datagenerator.engine.scxml.tags.boundary.BoundaryDate.java
License:Apache License
/** * @param isNullable isNullable/*w w w . j a v a 2 s . c om*/ * @param earliest lower boundary date * @param latest upper boundary date * @param onlyBusinessDays only business days * @return a list of boundary dates */ public List<String> positiveCase(boolean isNullable, String earliest, String latest, boolean onlyBusinessDays) { List<String> values = new LinkedList<>(); if (earliest.equalsIgnoreCase(latest)) { values.add(earliest); if (isNullable) { values.add(""); } return values; } DateTimeFormatter parser = ISODateTimeFormat.date(); DateTime earlyDate = parser.parseDateTime(earliest); DateTime lateDate = parser.parseDateTime(latest); String earlyDay = parser.print(earlyDate); String nextDay = getNextDay(earlyDate.toString().substring(0, 10), onlyBusinessDays); String prevDay = getPreviousDay(lateDate.toString().substring(0, 10), onlyBusinessDays); String lateDay = parser.print(lateDate); values.add(earlyDay); values.add(nextDay); values.add(prevDay); values.add(lateDay); if (isNullable) { values.add(""); } return values; }
From source file:org.finra.datagenerator.engine.scxml.tags.boundary.BoundaryDate.java
License:Apache License
/** * @param isNullable isNullable//from w w w . j a v a 2 s .c om * @param earliest lower boundary date * @param latest upper boundary date * @return a list of boundary dates */ public List<String> negativeCase(boolean isNullable, String earliest, String latest) { List<String> values = new LinkedList<>(); DateTimeFormatter parser = ISODateTimeFormat.date(); DateTime earlyDate = parser.parseDateTime(earliest); DateTime lateDate = parser.parseDateTime(latest); String prevDay = parser.print(earlyDate.minusDays(1)); String nextDay = parser.print(lateDate.plusDays(1)); values.add(prevDay); values.add(nextDay); values.add(nextDay.substring(5, 7) + "-" + nextDay.substring(8, 10) + "-" + nextDay.substring(0, 4)); values.add(getRandomHoliday(earliest, latest)); if (!isNullable) { values.add(""); } return values; }
From source file:org.finra.datagenerator.engine.scxml.tags.boundary.BoundaryDate.java
License:Apache License
/** * Grab random holiday from the equivalence class that falls between the two dates * * @param earliest the earliest date parameter as defined in the model * @param latest the latest date parameter as defined in the model * @return a holiday that falls between the dates *///from w w w. j av a 2 s. c om public String getRandomHoliday(String earliest, String latest) { String dateString = ""; DateTimeFormatter parser = ISODateTimeFormat.date(); DateTime earlyDate = parser.parseDateTime(earliest); DateTime lateDate = parser.parseDateTime(latest); List<Holiday> holidays = new LinkedList<>(); int min = Integer.parseInt(earlyDate.toString().substring(0, 4)); int max = Integer.parseInt(lateDate.toString().substring(0, 4)); int range = max - min + 1; int randomYear = (int) (Math.random() * range) + min; for (Holiday s : EquivalenceClassTransformer.HOLIDAYS) { holidays.add(s); } Collections.shuffle(holidays); for (Holiday holiday : holidays) { dateString = convertToReadableDate(holiday.forYear(randomYear)); if (toDate(dateString).after(toDate(earliest)) && toDate(dateString).before(toDate(latest))) { break; } } return dateString; }
From source file:org.finra.datagenerator.engine.scxml.tags.boundary.BoundaryDate.java
License:Apache License
/** * Given a year, month, and day, find the number of occurrences of that day in the month * * @param year the year// w w w. j a v a 2 s .com * @param month the month * @param day the day * @return the number of occurrences of the day in the month */ public int numOccurrences(int year, int month, int day) { DateTimeFormatter parser = ISODateTimeFormat.date(); DateTime date = parser.parseDateTime(year + "-" + month + "-" + "01"); Calendar cal = Calendar.getInstance(); cal.setTime(date.toDate()); GregorianChronology calendar = GregorianChronology.getInstance(); DateTimeField field = calendar.dayOfMonth(); int days = 0; int count = 0; int num = field.getMaximumValue(new LocalDate(year, month, day, calendar)); while (days < num) { if (cal.get(Calendar.DAY_OF_WEEK) == day) { count++; } date = date.plusDays(1); cal.setTime(date.toDate()); days++; } return count; }
From source file:org.finra.datagenerator.engine.scxml.tags.boundary.BoundaryDate.java
License:Apache License
/** * Convert the holiday format from EquivalenceClassTransformer into a date format * * @param holiday the date/* w w w. j a v a 2 s . co m*/ * @return a date String in the format yyyy-MM-dd */ public String convertToReadableDate(Holiday holiday) { DateTimeFormatter parser = ISODateTimeFormat.date(); if (holiday.isInDateForm()) { String month = Integer.toString(holiday.getMonth()).length() < 2 ? "0" + holiday.getMonth() : Integer.toString(holiday.getMonth()); String day = Integer.toString(holiday.getDayOfMonth()).length() < 2 ? "0" + holiday.getDayOfMonth() : Integer.toString(holiday.getDayOfMonth()); return holiday.getYear() + "-" + month + "-" + day; } else { /* * 5 denotes the final occurrence of the day in the month. Need to find actual * number of occurrences */ if (holiday.getOccurrence() == 5) { holiday.setOccurrence( numOccurrences(holiday.getYear(), holiday.getMonth(), holiday.getDayOfWeek())); } DateTime date = parser.parseDateTime(holiday.getYear() + "-" + holiday.getMonth() + "-" + "01"); Calendar calendar = Calendar.getInstance(); calendar.setTime(date.toDate()); int count = 0; while (count < holiday.getOccurrence()) { if (calendar.get(Calendar.DAY_OF_WEEK) == holiday.getDayOfWeek()) { count++; if (count == holiday.getOccurrence()) { break; } } date = date.plusDays(1); calendar.setTime(date.toDate()); } return date.toString().substring(0, 10); } }
From source file:org.fuin.objects4j.common.LocalDateAdapter.java
License:Open Source License
@Override public final String marshal(final LocalDate value) { if (value == null) { return null; }/* www . j av a 2 s. c o m*/ return ISODateTimeFormat.date().print(value); }
From source file:org.fuin.objects4j.common.LocalDateAdapter.java
License:Open Source License
@Override public final String convertToDatabaseColumn(final LocalDate value) { if (value == null) { return null; }//from w w w. j a v a 2 s .c om return ISODateTimeFormat.date().print(value); }