public CalendarDate makeCalendarDateFromOffset(String offset) { return CalendarDateFormatter.isoStringToCalendarDate(calendar, offset); }
public static void main(String arg[]) { CalendarDate cd = CalendarDate.present(); /* {"S", "M", "L", "F", "-"} System.out.printf("%s%n", DateTimeFormat.forStyle("SS").print(cd.getDateTime())); System.out.printf("%s%n", DateTimeFormat.forStyle("MM").print(cd.getDateTime())); System.out.printf("%s%n", DateTimeFormat.forStyle("LL").print(cd.getDateTime())); System.out.printf("%s%n", DateTimeFormat.forStyle("FF").print(cd.getDateTime())); */ System.out.printf("%s%n", cd); System.out.printf("toDateTimeStringISO=%s%n", toDateTimeStringISO(cd)); System.out.printf(" toDateTimeString=%s%n", toDateTimeString(cd)); System.out.printf(" toDateString=%s%n", toDateString(cd)); System.out.printf(" toTimeUnits=%s%n", toTimeUnits(cd)); System.out.printf("===============================%n"); Date d = cd.toDate(); System.out.printf("cd.toDate()=%s%n", toDateTimeString(d)); SimpleDateFormat udunitDF = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, Locale.US); udunitDF.setTimeZone(TimeZone.getTimeZone("UTC")); udunitDF.applyPattern("yyyy-MM-dd HH:mm:ss.SSS 'UTC'"); System.out.printf(" udunitDF=%s%n", udunitDF.format(d)); System.out.printf("===============================%n"); DateFormatter df = new DateFormatter(); System.out.printf(" toTimeUnits(date)=%s%n", toTimeUnits(cd)); System.out.printf("toDateTimeString(date)=%s%n", df.toDateTimeString(d)); System.out.printf("toDateOnlyString(date)=%s%n", df.toDateOnlyString(d)); }
static public String makeName(String collectionName, CalendarDate runtime) { String nameNoBlanks = StringUtil2.replace(collectionName, ' ', "_"); return nameNoBlanks + "-" + cf.toString(runtime); }
/** * Same as DateFormatter.toDateOnlyString() * * @return formatted date */ public String toDateString() { if (isPresent()) return CalendarDateFormatter.toDateStringPresent(); else return CalendarDateFormatter.toDateString(date); }
public static void main(String arg[]) { CalendarDate cd = CalendarDate.present(); /* {"S", "M", "L", "F", "-"} System.out.printf("%s%n", DateTimeFormat.forStyle("SS").print(cd.getDateTime())); System.out.printf("%s%n", DateTimeFormat.forStyle("MM").print(cd.getDateTime())); System.out.printf("%s%n", DateTimeFormat.forStyle("LL").print(cd.getDateTime())); System.out.printf("%s%n", DateTimeFormat.forStyle("FF").print(cd.getDateTime())); */ System.out.printf("%s%n", cd); System.out.printf("%s%n", toDateTimeStringISO(cd)); System.out.printf("%s%n", toDateTimeString(cd)); System.out.printf("%s%n", toDateString(cd)); Date d = new Date(); System.out.printf("%s%n", toDateTimeString(d)); DateFormatter df = new DateFormatter(); System.out.printf("%s%n", df.toDateTimeString(d)); System.out.printf("%s%n", df.toDateOnlyString(d)); }
@Test public void testCalendarToDate() { CalendarDate cdate = CalendarDateFormatter.isoStringToCalendarDate(Calendar.uniform30day, "1968-01-30T15:00:00.000Z"); System.out.printf("%s%n", cdate); System.out.printf("%s%n", cdate.getDateTime()); System.out.printf("%s%n", cdate.toDate()); System.out.printf("%s%n", CalendarDateFormatter.toDateTimeStringISO(cdate.toDate())); System.out.printf("%s%n", CalendarDateFormatter.toDateString(cdate)); CalendarDateFormatter cdf = new CalendarDateFormatter("yyyyMMdd"); System.out.printf("%s%n", cdf.toString(cdate)); }
/** * ISO formatted string * @return ISO8601 format (yyyy-MM-ddTHH:mm:ss.SSSZ) */ @Override public String toString() { return CalendarDateFormatter.toDateTimeStringISO(this); }
private void assertAddReturnsExpectedDate(String baseDate, double value, Field units, String expectedResult) { CalendarDate base = CalendarDateFormatter.isoStringToCalendarDate(Calendar.gregorian, baseDate); CalendarDate result = base.add(value, units); assertEquals(units.toString(), expectedResult, CalendarDateFormatter.toDateTimeStringISO(result)); }
logger.debug("tc = {}", tc); CalendarDate got = tc.getStart().getCalendarDate(); CalendarDate want = CalendarDateFormatter.isoStringToCalendarDate(null, "1999-11-16T12:00:00"); assert got.equals(want); assert tc.getResolution() == null; assert CalendarDateFormatter.toDateString(start).equals("2017-02-30"); assert CalendarDateFormatter.toDateString(end).equals("2017-04-01");
/** * Return a string with a reasonable and complete representation of the * given <code>Date</code>, shown in UTC. * * @param date <code>Date</code> to be represented * @return a string containing the representation of the date */ public static String formatDate(Date date) { return CalendarDateFormatter.toDateTimeString(date); }
public static CalendarDate parseISOformatOld(String calendarName, String isoDateString) { // Date date = CalendarDateFormatter.parseISODate(isoDateString); java.util.Date date = CalendarDateFormatter.isoStringToDate(isoDateString); Calendar cal = Calendar.get(calendarName); Chronology chronology = Calendar.getChronology(cal); DateTime dt = new DateTime(date, chronology); return new CalendarDate(cal, dt); }
private List<CollectionManager> makePartitionsByPeriod() throws IOException { this.type = Type.timePeriod; List<DatedMFile> files = new ArrayList<DatedMFile>(); for (MFile mfile : getFiles()) { CalendarDate cdate = dateExtractor.getCalendarDate(mfile); if (cdate == null) logger.error("Date extraction failed on file= {} dateExtractor = {}", mfile.getPath(), dateExtractor); files.add( new DatedMFile(mfile, cdate)); } Collections.sort(files); CalendarDateFormatter cdf = new CalendarDateFormatter("yyyyMMdd"); List<CollectionManager> result = new ArrayList<CollectionManager>(); TimePartitionCollectionManager curr = null; for (DatedMFile dmf : files) { if ((curr == null) || (!curr.endPartition.isAfter(dmf.cdate))) { CalendarPeriod period = CalendarPeriod.of(config.timePartition); CalendarDate start = dmf.cdate.truncate(period.getField()); // start on a boundary CalendarDate end = start.add( period); String name = collectionName + "-"+ cdf.toString(dmf.cdate); curr = new TimePartitionCollectionManager(name, start, end, getRoot(), this.auxInfo, this.logger); result.add(curr); } curr.add(dmf); } return result; }
boolean scheduleWrite(Message m) throws IOException { CalendarDate cd = m.ids.getReferenceTime(); String writerName = (dayRollover) ? fileout + "." + CalendarDateFormatter.toDateString(cd) : fileout; File dir2 = new File(dispatchDir, catDir); if (!dir2.exists() && !dir2.mkdirs()) logger.warn("Failed to make " + dir2.getPath()); String filename = (dayRollover) ? fileout + "." + CalendarDateFormatter.toDateString(cd) : fileout; file2write = new File(dir2, filename + ".bufr");
DateTime dt = parseIsoTimeString(calt, iso); return new CalendarDate(calt, dt);
static public CalendarDateFormatter factory(CalendarPeriod period) { switch (period.getField()) { case Year: return new CalendarDateFormatter("yyyy"); case Month: return new CalendarDateFormatter("yyyy-MM"); case Day: return new CalendarDateFormatter("yyyy-MM-dd"); case Hour: return new CalendarDateFormatter("yyyy-MM-ddTHH"); default: return new CalendarDateFormatter("yyyy-MM-ddTHH:mm:ss"); } }
/** * ISO formatted string * @return ISO8601 format (yyyy-MM-ddTHH:mm:ss.SSSZ) */ @Override public String toString() { return CalendarDateFormatter.toDateTimeStringISO(this); }
/** * Same as DateFormatter.toDateOnlyString() * * @return formatted date */ public String toDateString() { if (isPresent()) return CalendarDateFormatter.toDateStringPresent(); else return CalendarDateFormatter.toDateString(date); }
/** * Return a string with a reasonable and complete representation of the * given <code>Date</code>, shown in UTC. * * @param date <code>Date</code> to be represented * @return a string containing the representation of the date */ public static String formatDate(Date date) { return CalendarDateFormatter.toDateTimeString(date); }
public static CalendarDate parseISOformatOld(String calendarName, String isoDateString) { // Date date = CalendarDateFormatter.parseISODate(isoDateString); java.util.Date date = CalendarDateFormatter.isoStringToDate(isoDateString); Calendar cal = Calendar.get(calendarName); Chronology chronology = Calendar.getChronology(cal); DateTime dt = new DateTime(date, chronology); return new CalendarDate(cal, dt); }
DateTime dt = parseIsoTimeString(calt, iso); Calendar useCal = Calendar.of(dt.getChronology()); return new CalendarDate(useCal, dt);