Java Code Examples for org.joda.time.format.ISODateTimeFormat#dateTime()
The following examples show how to use
org.joda.time.format.ISODateTimeFormat#dateTime() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Time_18_GJChronology_s.java From coming with MIT License | 6 votes |
/** * Gets a debugging toString. * * @return a debugging string */ public String toString() { StringBuffer sb = new StringBuffer(60); sb.append("GJChronology"); sb.append('['); sb.append(getZone().getID()); if (iCutoverMillis != DEFAULT_CUTOVER.getMillis()) { sb.append(",cutover="); DateTimeFormatter printer; if (withUTC().dayOfYear().remainder(iCutoverMillis) == 0) { printer = ISODateTimeFormat.date(); } else { printer = ISODateTimeFormat.dateTime(); } printer.withChronology(withUTC()).printTo(sb, iCutoverMillis); } if (getMinimumDaysInFirstWeek() != 4) { sb.append(",mdfw="); sb.append(getMinimumDaysInFirstWeek()); } sb.append(']'); return sb.toString(); }
Example 2
Source File: FragmentHandler.java From dremio-oss with Apache License 2.0 | 6 votes |
void checkStateAndLogIfNecessary() { if (!fragmentStarted) { final DateTimeFormatter formatter = ISODateTimeFormat.dateTime(); if (canceled.get()) { logger.warn("Received cancel request at {} for fragment {} that was never started", formatter.print(cancellationTime), QueryIdHelper.getQueryIdentifier(handle)); } FragmentEvent event; while ((event = finishedReceivers.poll()) != null) { logger.warn("Received early fragment termination at {} for path {} {} -> {} for a fragment that was never started", formatter.print(event.time), QueryIdHelper.getQueryId(handle.getQueryId()), QueryIdHelper.getFragmentId(event.handle), QueryIdHelper.getFragmentId(handle) ); } } }
Example 3
Source File: Time_6_GJChronology_t.java From coming with MIT License | 6 votes |
/** * Gets a debugging toString. * * @return a debugging string */ public String toString() { StringBuffer sb = new StringBuffer(60); sb.append("GJChronology"); sb.append('['); sb.append(getZone().getID()); if (iCutoverMillis != DEFAULT_CUTOVER.getMillis()) { sb.append(",cutover="); DateTimeFormatter printer; if (withUTC().dayOfYear().remainder(iCutoverMillis) == 0) { printer = ISODateTimeFormat.date(); } else { printer = ISODateTimeFormat.dateTime(); } printer.withChronology(withUTC()).printTo(sb, iCutoverMillis); } if (getMinimumDaysInFirstWeek() != 4) { sb.append(",mdfw="); sb.append(getMinimumDaysInFirstWeek()); } sb.append(']'); return sb.toString(); }
Example 4
Source File: DateFormatterTest.java From twiliochat-android with MIT License | 6 votes |
@Test public void testGetDateFromISOString() { String inputDate = "2015-10-21T07:28:00.000Z"; DateTimeFormatter isoFormatter = ISODateTimeFormat.dateTime(); DateTime date = null; try { date = isoFormatter.parseDateTime(inputDate); } catch (IllegalArgumentException e) { e.printStackTrace(); } DateTime outputDate = DateFormatter.getDateFromISOString(inputDate); assertEquals(outputDate, date); }
Example 5
Source File: DateTimeFormatterFactory.java From spring-analysis-note with MIT License | 5 votes |
/** * Create a new {@code DateTimeFormatter} using this factory. * <p>If no specific pattern or style has been defined, * the supplied {@code fallbackFormatter} will be used. * @param fallbackFormatter the fall-back formatter to use * when no specific factory properties have been set * @return a new date time formatter */ public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter) { DateTimeFormatter dateTimeFormatter = null; if (StringUtils.hasLength(this.pattern)) { dateTimeFormatter = DateTimeFormat.forPattern(this.pattern); } else if (this.iso != null && this.iso != ISO.NONE) { switch (this.iso) { case DATE: dateTimeFormatter = ISODateTimeFormat.date(); break; case TIME: dateTimeFormatter = ISODateTimeFormat.time(); break; case DATE_TIME: dateTimeFormatter = ISODateTimeFormat.dateTime(); break; default: throw new IllegalStateException("Unsupported ISO format: " + this.iso); } } else if (StringUtils.hasLength(this.style)) { dateTimeFormatter = DateTimeFormat.forStyle(this.style); } if (dateTimeFormatter != null && this.timeZone != null) { dateTimeFormatter = dateTimeFormatter.withZone(DateTimeZone.forTimeZone(this.timeZone)); } return (dateTimeFormatter != null ? dateTimeFormatter : fallbackFormatter); }
Example 6
Source File: DateTimeFormatterFactory.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Create a new {@code DateTimeFormatter} using this factory. * <p>If no specific pattern or style has been defined, * the supplied {@code fallbackFormatter} will be used. * @param fallbackFormatter the fall-back formatter to use when no specific * factory properties have been set (can be {@code null}). * @return a new date time formatter */ public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter) { DateTimeFormatter dateTimeFormatter = null; if (StringUtils.hasLength(this.pattern)) { dateTimeFormatter = DateTimeFormat.forPattern(this.pattern); } else if (this.iso != null && this.iso != ISO.NONE) { switch (this.iso) { case DATE: dateTimeFormatter = ISODateTimeFormat.date(); break; case TIME: dateTimeFormatter = ISODateTimeFormat.time(); break; case DATE_TIME: dateTimeFormatter = ISODateTimeFormat.dateTime(); break; case NONE: /* no-op */ break; default: throw new IllegalStateException("Unsupported ISO format: " + this.iso); } } else if (StringUtils.hasLength(this.style)) { dateTimeFormatter = DateTimeFormat.forStyle(this.style); } if (dateTimeFormatter != null && this.timeZone != null) { dateTimeFormatter = dateTimeFormatter.withZone(DateTimeZone.forTimeZone(this.timeZone)); } return (dateTimeFormatter != null ? dateTimeFormatter : fallbackFormatter); }
Example 7
Source File: BaseSpringContentRestTestCase.java From flowable-engine with Apache License 2.0 | 5 votes |
/** * Extract a date from the given string. Assertion fails when invalid date has been provided. */ protected Date getDateFromISOString(String isoString) { DateTimeFormatter dateFormat = ISODateTimeFormat.dateTime(); try { return dateFormat.parseDateTime(isoString).toDate(); } catch (IllegalArgumentException iae) { fail("Illegal date provided: " + isoString); return null; } }
Example 8
Source File: UtilsTest.java From amforeas with GNU General Public License v3.0 | 5 votes |
@Test public void testIsDateTime () { DateTimeFormatter df = ISODateTimeFormat.dateTime(); DateTime date = df.parseDateTime("2011-12-11T12:35:45.200+01:00"); assertEquals(date, AmforeasUtils.isDateTime("2011-12-11T12:35:45.200+01:00")); assertNull(AmforeasUtils.isDateTime("2011-12-11 22:00:00")); assertNull(AmforeasUtils.isDateTime("")); assertNull(AmforeasUtils.isDateTime(null)); assertNull(AmforeasUtils.isDateTime("2011-01-19")); assertNull(AmforeasUtils.isDateTime("20110119")); assertNull(AmforeasUtils.isDateTime("22:00:00")); assertNull(AmforeasUtils.isDateTime("12:35:45.200+01:00")); }
Example 9
Source File: AmforeasUtils.java From amforeas with GNU General Public License v3.0 | 5 votes |
/** * Check if a string has the ISO date time format. Uses the ISODateTimeFormat.dateTime() from JodaTime * and returns a DateTime instance. The correct format is yyyy-MM-ddTHH:mm:ss.SSSZ * @param arg the string to check * @return a DateTime instance if the string is in the correct ISO format. */ public static DateTime isDateTime (final String arg) { if (arg == null) return null; DateTimeFormatter f = ISODateTimeFormat.dateTime(); DateTime ret = null; try { ret = f.parseDateTime(arg); } catch (IllegalArgumentException e) { l.debug("{} is not a valid ISO DateTime", arg); } return ret; }
Example 10
Source File: DateTimeFormatterFactory.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Create a new {@code DateTimeFormatter} using this factory. * <p>If no specific pattern or style has been defined, * the supplied {@code fallbackFormatter} will be used. * @param fallbackFormatter the fall-back formatter to use when no specific * factory properties have been set (can be {@code null}). * @return a new date time formatter */ public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter) { DateTimeFormatter dateTimeFormatter = null; if (StringUtils.hasLength(this.pattern)) { dateTimeFormatter = DateTimeFormat.forPattern(this.pattern); } else if (this.iso != null && this.iso != ISO.NONE) { switch (this.iso) { case DATE: dateTimeFormatter = ISODateTimeFormat.date(); break; case TIME: dateTimeFormatter = ISODateTimeFormat.time(); break; case DATE_TIME: dateTimeFormatter = ISODateTimeFormat.dateTime(); break; case NONE: /* no-op */ break; default: throw new IllegalStateException("Unsupported ISO format: " + this.iso); } } else if (StringUtils.hasLength(this.style)) { dateTimeFormatter = DateTimeFormat.forStyle(this.style); } if (dateTimeFormatter != null && this.timeZone != null) { dateTimeFormatter = dateTimeFormatter.withZone(DateTimeZone.forTimeZone(this.timeZone)); } return (dateTimeFormatter != null ? dateTimeFormatter : fallbackFormatter); }
Example 11
Source File: StructuredSyslogServerEvent.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
public DateTimeFormatter getDateTimeFormatter() { if (dateTimeFormatter == null) { this.dateTimeFormatter = ISODateTimeFormat.dateTime(); } return dateTimeFormatter; }
Example 12
Source File: StorageAdminAPI.java From chipster with MIT License | 5 votes |
public void onChipsterMessage(ChipsterMessage msg) { ParameterMessage resultMessage = (ParameterMessage) msg; String usernamesString = resultMessage.getNamedParameter(ParameterMessage.PARAMETER_USERNAME_LIST); String namesString = resultMessage.getNamedParameter(ParameterMessage.PARAMETER_SESSION_NAME_LIST); String sizesString = resultMessage.getNamedParameter(ParameterMessage.PARAMETER_SIZE_LIST); String datesString = resultMessage.getNamedParameter(ParameterMessage.PARAMETER_DATE_LIST); String idsString = resultMessage.getNamedParameter(ParameterMessage.PARAMETER_SESSION_UUID_LIST); String quotaString = resultMessage.getNamedParameter(ParameterMessage.PARAMETER_QUOTA); String quotaWarningString = resultMessage.getNamedParameter(ParameterMessage.PARAMETER_QUOTA_WARNING); String storageUsageString = resultMessage.getNamedParameter(ParameterMessage.PARAMETER_SIZE); String[] usernames = Strings.splitUnlessEmpty(usernamesString, "\t"); String[] names = Strings.splitUnlessEmpty(namesString, "\t"); String[] sizes = Strings.splitUnlessEmpty(sizesString, "\t"); String[] dates = Strings.splitUnlessEmpty(datesString, "\t"); String[] ids = Strings.splitUnlessEmpty(idsString, "\t"); DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime(); entries = new LinkedList<StorageEntry>(); for (int i = 0; i < names.length; i++) { StorageEntry entry = new StorageEntry(); entry.setDate(dateTimeFormatter.parseDateTime(dates[i]).toDate()); entry.setUsername(usernames[i]); entry.setSize(Long.parseLong(sizes[i])); entry.setName(names[i]); entry.setID(ids[i]); entries.add(entry); } quota = Long.parseLong(quotaString); quotaWarning = Long.parseLong(quotaWarningString); storageUsage = Long.parseLong(storageUsageString); latch.countDown(); }
Example 13
Source File: DateTimeFormatterFactory.java From java-technology-stack with MIT License | 5 votes |
/** * Create a new {@code DateTimeFormatter} using this factory. * <p>If no specific pattern or style has been defined, * the supplied {@code fallbackFormatter} will be used. * @param fallbackFormatter the fall-back formatter to use * when no specific factory properties have been set * @return a new date time formatter */ public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter) { DateTimeFormatter dateTimeFormatter = null; if (StringUtils.hasLength(this.pattern)) { dateTimeFormatter = DateTimeFormat.forPattern(this.pattern); } else if (this.iso != null && this.iso != ISO.NONE) { switch (this.iso) { case DATE: dateTimeFormatter = ISODateTimeFormat.date(); break; case TIME: dateTimeFormatter = ISODateTimeFormat.time(); break; case DATE_TIME: dateTimeFormatter = ISODateTimeFormat.dateTime(); break; default: throw new IllegalStateException("Unsupported ISO format: " + this.iso); } } else if (StringUtils.hasLength(this.style)) { dateTimeFormatter = DateTimeFormat.forStyle(this.style); } if (dateTimeFormatter != null && this.timeZone != null) { dateTimeFormatter = dateTimeFormatter.withZone(DateTimeZone.forTimeZone(this.timeZone)); } return (dateTimeFormatter != null ? dateTimeFormatter : fallbackFormatter); }
Example 14
Source File: BoundaryTimerEventRepeatCompatibilityTest.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
@Deployment public void testRepeatWithoutEnd() throws Throwable { Clock clock = processEngineConfiguration.getClock(); Calendar calendar = Calendar.getInstance(); Date baseTime = calendar.getTime(); calendar.add(Calendar.MINUTE, 20); //expect to stop boundary jobs after 20 minutes DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); DateTime dt = new DateTime(calendar.getTime()); String dateStr = fmt.print(dt); //reset the timer Calendar nextTimeCal = Calendar.getInstance(); nextTimeCal.setTime(baseTime); clock.setCurrentCalendar(nextTimeCal); processEngineConfiguration.setClock(clock); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("repeatWithEnd"); runtimeService.setVariable(processInstance.getId(), "EndDateForBoundary", dateStr); List<Task> tasks = taskService.createTaskQuery().list(); assertEquals(1, tasks.size()); Task task = tasks.get(0); assertEquals("Task A", task.getName()); // Test Boundary Events // complete will cause timer to be created taskService.complete(task.getId()); List<Job> jobs = managementService.createTimerJobQuery().list(); assertEquals(1, jobs.size()); //boundary events waitForJobExecutorToProcessAllJobs(2000, 200); // a new job must be prepared because there are 10 repeats 2 seconds interval for (int i = 0; i < 9; i++) { nextTimeCal.add(Calendar.SECOND, 2); clock.setCurrentCalendar(nextTimeCal); processEngineConfiguration.setClock(clock); waitForJobExecutorToProcessAllJobsAndExecutableTimerJobs(2000, 200); } nextTimeCal.add(Calendar.SECOND, 2); clock.setCurrentCalendar(nextTimeCal); processEngineConfiguration.setClock(clock); waitForJobExecutorToProcessAllJobs(2000, 200); // Should not have any other jobs because the endDate is reached jobs = managementService.createTimerJobQuery().list(); assertEquals(0, jobs.size()); tasks = taskService.createTaskQuery().list(); task = tasks.get(0); assertEquals("Task B", task.getName()); assertEquals(1, tasks.size()); taskService.complete(task.getId()); waitForJobExecutorToProcessAllJobs(2000, 200); // now All the process instances should be completed List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().list(); assertEquals(0, processInstances.size()); // no jobs jobs = managementService.createJobQuery().list(); assertEquals(0, jobs.size()); jobs = managementService.createTimerJobQuery().list(); assertEquals(0, jobs.size()); // no tasks tasks = taskService.createTaskQuery().list(); assertEquals(0, tasks.size()); processEngineConfiguration.resetClock(); }
Example 15
Source File: AbstractJodaFormattingProcessorTest.java From super-csv with Apache License 2.0 | 4 votes |
@Test(expected = NullPointerException.class) public void testConstructor4WithNullJodaType() { new FmtNothing(null, ISODateTimeFormat.dateTime(), new IdentityTransform()); }
Example 16
Source File: Helpers.java From gsn with GNU General Public License v3.0 | 4 votes |
public static String convertTimeFromLongToIso(long timestamp) { DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); DateTime dt = new DateTime(timestamp); return fmt.print(dt); }
Example 17
Source File: TimeUtils.java From jersey-hmac-auth with Apache License 2.0 | 4 votes |
public static String getCurrentTimestamp() { DateTimeFormatter formatter = ISODateTimeFormat.dateTime(); return formatter.print(nowInUTC()); }
Example 18
Source File: ConvertTimeStampToString.java From Bats with Apache License 2.0 | 4 votes |
public ConvertTimeStampToString(ScalarWriter baseWriter) { super(baseWriter); final String formatValue = baseWriter.schema().format(); dateTimeFormatter = formatValue == null ? ISODateTimeFormat.dateTime() : DateTimeFormat.forPattern(formatValue); }
Example 19
Source File: DateMidnightConverter.java From gson-jodatime-serialisers with MIT License | 3 votes |
/** * Gson invokes this call-back method during deserialization when it encounters a field of the * specified type. <p> * * In the implementation of this call-back method, you should consider invoking * {@link com.google.gson.JsonDeserializationContext#deserialize(com.google.gson.JsonElement, java.lang.reflect.Type)} method to create objects * for any non-trivial field of the returned object. However, you should never invoke it on the * the same type passing {@code json} since that will cause an infinite loop (Gson will call your * call-back method again). * @param json The Json data being deserialized * @param typeOfT The type of the Object to deserialize to * @return a deserialized object of the specified type typeOfT which is a subclass of {@code T} * @throws com.google.gson.JsonParseException if json is not in the expected format of {@code typeOfT} */ @Override public DateMidnight deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { // Do not try to deserialize null or empty values if (json.getAsString() == null || json.getAsString().isEmpty()) { return null; } final DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); return new DateMidnight(fmt.parseDateTime(json.getAsString())); }
Example 20
Source File: DateMidnightConverter.java From gson-jodatime-serialisers with MIT License | 3 votes |
/** * Gson invokes this call-back method during serialization when it encounters a field of the * specified type. <p> * * In the implementation of this call-back method, you should consider invoking * {@link com.google.gson.JsonSerializationContext#serialize(Object, java.lang.reflect.Type)} method to create JsonElements for any * non-trivial field of the {@code src} object. However, you should never invoke it on the * {@code src} object itself since that will cause an infinite loop (Gson will call your * call-back method again). * @param src the object that needs to be converted to Json. * @param typeOfSrc the actual type (fully genericized version) of the source object. * @return a JsonElement corresponding to the specified object. */ @Override public JsonElement serialize(DateMidnight src, Type typeOfSrc, JsonSerializationContext context) { final DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); return new JsonPrimitive(fmt.print(src)); }