Example usage for org.joda.time.format ISODateTimeFormat dateTime

List of usage examples for org.joda.time.format ISODateTimeFormat dateTime

Introduction

In this page you can find the example usage for org.joda.time.format ISODateTimeFormat dateTime.

Prototype

public static DateTimeFormatter dateTime() 

Source Link

Document

Returns a formatter that combines a full date and time, separated by a 'T' (yyyy-MM-dd'T'HH:mm:ss.SSSZZ).

Usage

From source file:org.activiti.engine.test.bpmn.event.timer.BoundaryTimerEventRepeatWithEnd.java

License:Apache License

@Deployment
public void testRepeatWithEnd() throws Throwable {

    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);/*w  w  w .  java2s .c o  m*/
    processEngineConfiguration.getClock().setCurrentTime(nextTimeCal.getTime());

    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.createJobQuery().list();
    assertEquals(1, jobs.size());
    //boundary events

    try {
        waitForJobExecutorToProcessAllJobs(2000, 200);
        fail("a new job must be prepared because there are 20 repeats 2 seconds interval");
    } catch (Exception ex) {
        //expected exception because a new job is prepared
    }

    nextTimeCal.add(Calendar.MINUTE, 15); //after 15 minutes
    processEngineConfiguration.getClock().setCurrentTime(nextTimeCal.getTime());

    try {
        waitForJobExecutorToProcessAllJobs(2000, 200);
        fail("a new job must be prepared because there are 20 repeats 2 seconds interval");
    } catch (Exception ex) {
        //expected exception because a new job is prepared
    }

    nextTimeCal.add(Calendar.MINUTE, 5); //after another 5 minutes (20 minutes and 1 second from the baseTime) the BoundaryEndTime is reached
    nextTimeCal.add(Calendar.SECOND, 1);
    processEngineConfiguration.getClock().setCurrentTime(nextTimeCal.getTime());

    try {
        waitForJobExecutorToProcessAllJobs(2000, 200);
    } catch (Exception ex) {
        fail("Should not have any other jobs because the endDate is reached");
    }
    tasks = taskService.createTaskQuery().list();
    task = tasks.get(0);
    assertEquals("Task B", task.getName());
    assertEquals(1, tasks.size());
    taskService.complete(task.getId());

    try {
        waitForJobExecutorToProcessAllJobs(2000, 500);
    } catch (Exception e) {
        // expected
        fail("No jobs should be active here.");

    }

}

From source file:org.activiti.rest.content.service.api.BaseSpringContentRestTestCase.java

License:Apache License

/**
 * Extract a date from the given string. Assertion fails when invalid date has been provided.
 *//*from ww w .j  a v  a2s .c  o  m*/
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;
    }
}

From source file:org.alfresco.repo.web.scripts.calendar.AbstractCalendarWebScript.java

License:Open Source License

/**
 * Removes the time zone for a given date if the Calendar Entry is an all day event
 * /*from  w  ww .java 2s .c o  m*/
 * @return ISO 8601 formatted date String if datePattern is null
 */
protected String removeTimeZoneIfRequired(Date date, Boolean isAllDay, Boolean removeTimezone,
        String datePattern) {
    if (removeTimezone) {
        DateTime dateTime = new DateTime(date, DateTimeZone.UTC);

        if (null == datePattern) {
            return dateTime
                    .toString((isAllDay) ? (ALL_DAY_DATETIME_FORMATTER) : (ISODateTimeFormat.dateTime()));
        } else {
            // For Legacy Dates and Times.
            return dateTime.toString(DateTimeFormat.forPattern(datePattern));
        }
    }

    // This is for all other cases, including the case, when UTC time zone is configured

    if (!isAllDay && (null == datePattern)) {
        return ISO8601DateFormat.format(date);
    }

    DateFormat simpleDateFormat = new SimpleDateFormat(
            (null != datePattern) ? (datePattern) : (ALL_DAY_DATETIME_PATTERN));

    return simpleDateFormat.format(date);
}

From source file:org.alfresco.util.CachingDateFormat.java

License:Open Source License

public static Pair<Date, Integer> lenientParse(String text, int minimumResolution) throws ParseException {
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    try {/* ww  w.  j  a v a  2  s.com*/
        Date parsed = fmt.parseDateTime(text).toDate();
        return new Pair<Date, Integer>(parsed, Calendar.MILLISECOND);
    } catch (IllegalArgumentException e) {

    }

    SimpleDateFormatAndResolution[] formatters = getLenientFormatters();
    for (SimpleDateFormatAndResolution formatter : formatters) {
        if (formatter.resolution >= minimumResolution) {
            ParsePosition pp = new ParsePosition(0);
            Date parsed = formatter.simpleDateFormat.parse(text, pp);
            if ((pp.getIndex() < text.length()) || (parsed == null)) {
                continue;
            }
            return new Pair<Date, Integer>(parsed, formatter.resolution);
        }
    }

    throw new ParseException("Unknown date format", 0);

}

From source file:org.apache.abdera2.activities.io.gson.DateAdapter.java

License:Apache License

protected String serialize(Date t) {
    return ISODateTimeFormat.dateTime().print(new DateTime(t));
}

From source file:org.apache.abdera2.activities.io.gson.DateTimeAdapter.java

License:Apache License

protected String serialize(DateTime t) {
    return ISODateTimeFormat.dateTime().print(t);
}

From source file:org.apache.archiva.webdav.ArchivaDavResource.java

License:Apache License

/**
 * Fill the set of properties//from  w  w w. j  av  a  2s  .com
 */
protected DavPropertySet initProperties() {
    if (!exists()) {
        properties = new DavPropertySet();
    }

    if (properties != null) {
        return properties;
    }

    DavPropertySet properties = new DavPropertySet();

    // set (or reset) fundamental properties
    if (getDisplayName() != null) {
        properties.add(new DefaultDavProperty(DavPropertyName.DISPLAYNAME, getDisplayName()));
    }
    if (isCollection()) {
        properties.add(new ResourceType(ResourceType.COLLECTION));
        // Windows XP support
        properties.add(new DefaultDavProperty(DavPropertyName.ISCOLLECTION, "1"));
    } else {
        properties.add(new ResourceType(ResourceType.DEFAULT_RESOURCE));

        // Windows XP support
        properties.add(new DefaultDavProperty(DavPropertyName.ISCOLLECTION, "0"));
    }

    // Need to get the ISO8601 date for properties
    DateTime dt = new DateTime(localResource.lastModified());
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    String modifiedDate = fmt.print(dt);

    properties.add(new DefaultDavProperty(DavPropertyName.GETLASTMODIFIED, modifiedDate));

    properties.add(new DefaultDavProperty(DavPropertyName.CREATIONDATE, modifiedDate));

    properties.add(new DefaultDavProperty(DavPropertyName.GETCONTENTLENGTH, localResource.length()));

    this.properties = properties;

    return properties;
}

From source file:org.apache.archiva.webdav.ArchivaVirtualDavResource.java

License:Apache License

/**
 * Fill the set of properties//ww  w .jav a  2  s  .c om
 */
protected void initProperties() {
    if (!exists() || propsInitialized) {
        return;
    }

    // set (or reset) fundamental properties
    if (getDisplayName() != null) {
        properties.add(new DefaultDavProperty(DavPropertyName.DISPLAYNAME, getDisplayName()));
    }
    if (isCollection()) {
        properties.add(new ResourceType(ResourceType.COLLECTION));
        // Windows XP support
        properties.add(new DefaultDavProperty(DavPropertyName.ISCOLLECTION, "1"));
    } else {
        properties.add(new ResourceType(ResourceType.DEFAULT_RESOURCE));

        // Windows XP support
        properties.add(new DefaultDavProperty(DavPropertyName.ISCOLLECTION, "0"));
    }

    // Need to get the ISO8601 date for properties
    DateTime dt = new DateTime(0);
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    String modifiedDate = fmt.print(dt);

    properties.add(new DefaultDavProperty(DavPropertyName.GETLASTMODIFIED, modifiedDate));

    properties.add(new DefaultDavProperty(DavPropertyName.CREATIONDATE, modifiedDate));

    properties.add(new DefaultDavProperty(DavPropertyName.GETCONTENTLENGTH, 0));

    propsInitialized = true;
}

From source file:org.apache.drill.exec.vector.complex.fn.BasicJsonOutput.java

License:Apache License

protected BasicJsonOutput(JsonGenerator gen, DateOutputFormat dateOutput) {
    Preconditions.checkNotNull(dateOutput);
    Preconditions.checkNotNull(gen);/*from  w  w  w.  ja v a 2s.  c o  m*/

    this.gen = gen;

    switch (dateOutput) {
    case SQL: {
        dateFormatter = DateUtility.formatDate;
        timeFormatter = DateUtility.formatTime;
        timestampFormatter = DateUtility.formatTimeStamp;
        break;
    }
    case ISO: {
        dateFormatter = ISODateTimeFormat.date();
        timeFormatter = ISODateTimeFormat.time();
        timestampFormatter = ISODateTimeFormat.dateTime();
        break;
    }

    default:
        throw new UnsupportedOperationException(
                String.format("Unable to support date output of type %s.", dateOutput));
    }
}

From source file:org.apache.druid.query.expression.TimestampFormatExprMacro.java

License:Apache License

@Override
public Expr apply(final List<Expr> args) {
    if (args.size() < 1 || args.size() > 3) {
        throw new IAE("Function[%s] must have 1 to 3 arguments", name());
    }//from w  ww  .  j  a va 2s  . c o m

    final Expr arg = args.get(0);
    final String formatString;
    final DateTimeZone timeZone;

    if (args.size() > 1) {
        Preconditions.checkArgument(args.get(1).isLiteral(), "Function[%s] format arg must be a literal",
                name());
        formatString = (String) args.get(1).getLiteralValue();
    } else {
        formatString = null;
    }

    if (args.size() > 2) {
        timeZone = ExprUtils.toTimeZone(args.get(2));
    } else {
        timeZone = DateTimeZone.UTC;
    }

    final DateTimeFormatter formatter = formatString == null ? ISODateTimeFormat.dateTime()
            : DateTimeFormat.forPattern(formatString).withZone(timeZone);

    class TimestampFormatExpr extends ExprMacroTable.BaseScalarUnivariateMacroFunctionExpr {
        private TimestampFormatExpr(Expr arg) {
            super(arg);
        }

        @Nonnull
        @Override
        public ExprEval eval(final ObjectBinding bindings) {
            ExprEval eval = arg.eval(bindings);
            if (eval.isNumericNull()) {
                // Return null if the argument if null.
                return ExprEval.of(null);
            }
            return ExprEval.of(formatter.print(arg.eval(bindings).asLong()));
        }

        @Override
        public Expr visit(Shuttle shuttle) {
            Expr newArg = arg.visit(shuttle);
            return shuttle.visit(new TimestampFormatExpr(newArg));
        }
    }

    return new TimestampFormatExpr(arg);
}