Example usage for org.joda.time DateTime parse

List of usage examples for org.joda.time DateTime parse

Introduction

In this page you can find the example usage for org.joda.time DateTime parse.

Prototype

@FromString
public static DateTime parse(String str) 

Source Link

Document

Parses a DateTime from the specified string.

Usage

From source file:org.apache.streams.util.DateUtil.java

License:Apache License

public static DateTime determineDate(String dateString) throws ParseException {
    // Trim the string just in case it is dirty.
    dateString = dateString.trim();/*from w w w  . ja v a 2s . c  o  m*/

    // check to see if it looks like it is millis. If so, parse as millis and return.
    if (dateString.matches(REGEX_ONLY_NUMBERS))
        return new DateTime(new Date(Long.parseLong(dateString)));

    try {
        // try to parse the string into a java.date object, if possible.
        SimpleDateFormat dateFormat = new SimpleDateFormat(determineDateFormat(dateString));
        dateFormat.setLenient(false);
        return new DateTime(dateFormat.parse(dateString));
    } catch (Exception e) {

    }

    return new DateTime(DateTime.parse(dateString));
}

From source file:org.biokoframework.system.services.authentication.token.impl.TokenAuthenticationServiceImpl.java

License:Open Source License

private boolean isExpired(Authentication authentication) {
    String expireStr = authentication.get(GenericFieldNames.AUTH_TOKEN_EXPIRE);
    DateTime expire = DateTime.parse(expireStr);

    return expire.isBefore(fTime.getCurrentTimeAsDateTime());
}

From source file:org.calrissian.accumulorecipes.eventstore.cli.DailyShardSplitter.java

License:Apache License

public static void main(String args[])
        throws AccumuloSecurityException, AccumuloException, TableNotFoundException {

    if (args.length != 7) {
        System.out.println("Usage: " + DailyShardSplitter.class.getName()
                + "<zookeepers> <instance> <username> <password> <tableName> <start day: yyyy-mm-dd> <stop day: yyyy-mm-dd>");
        System.exit(1);//w  ww .j  a  v  a 2s. c om
    }

    String zookeepers = args[0];
    String instance = args[1];
    String username = args[2];
    String password = args[3];
    String tableName = args[4];
    DateTime start = DateTime.parse(args[5]);
    DateTime stop = DateTime.parse(args[6]);

    Instance accInst = new ZooKeeperInstance(instance, zookeepers);
    Connector connector = accInst.getConnector(username, password.getBytes());

    SortedSet<Text> shards = new DailyShardBuilder(Constants.DEFAULT_PARTITION_SIZE)
            .buildShardsInRange(start.toDate(), stop.toDate());

    connector.tableOperations().addSplits(tableName, shards);
}

From source file:org.calrissian.accumulorecipes.thirdparty.pig.loader.MetricFeatureLoader.java

License:Apache License

@Override
public void setLocation(String uri, Job job) throws IOException {

    String path = uri.substring(uri.indexOf("://") + 3, uri.indexOf("?"));

    if (!isConnectorInfoSet(AccumuloInputFormat.class, job.getConfiguration())) {

        String[] indexAndShardTable = StringUtils.splitPreserveAllTokens(path, "/");
        if (indexAndShardTable.length != 1)
            throw new IOException("Path portion of URI must contain the metric table prefix " + USAGE);

        if (uri.startsWith("metrics")) {
            String queryPortion = uri.substring(uri.indexOf("?") + 1, uri.length());
            Multimap<String, String> queryParams = UriUtils.splitQuery(queryPortion);

            String accumuloUser = getProp(queryParams, "user");
            String accumuloPass = getProp(queryParams, "pass");
            String accumuloInst = getProp(queryParams, "inst");
            String zookeepers = getProp(queryParams, "zk");
            if (accumuloUser == null || accumuloPass == null || accumuloInst == null || zookeepers == null)
                throw new IOException(
                        "Some Accumulo connection information is missing. Must supply username, password, instance, and zookeepers. "
                                + USAGE);

            String timeUnitStr = getProp(queryParams, "timeUnit");
            if (timeUnitStr != null)
                timeUnit = TimeUnit.valueOf(timeUnitStr.toUpperCase());
            else//from  w ww.j  av  a 2 s  . co m
                throw new IOException("A valid TimeUnit must be supplied. " + USAGE);

            String group = getProp(queryParams, "group");
            String type = getProp(queryParams, "type");
            String name = getProp(queryParams, "name");

            String startTime = getProp(queryParams, "start");
            String endTime = getProp(queryParams, "end");
            if (startTime == null || endTime == null)
                throw new IOException("Start and end times are required. " + USAGE);

            String auths = getProp(queryParams, "auths");
            if (auths == null)
                auths = ""; // default to empty auths

            DateTime startDT = DateTime.parse(startTime);
            DateTime endDT = DateTime.parse(endTime);

            FeaturesInputFormat.setZooKeeperInstance(job, accumuloInst, zookeepers);
            try {
                FeaturesInputFormat.setInputInfo(job, accumuloUser, accumuloPass.getBytes(),
                        new Authorizations(auths.getBytes()));
            } catch (AccumuloSecurityException e) {
                throw new RuntimeException(e);
            }
            try {
                FeaturesInputFormat.setQueryInfo(job, startDT.toDate(), endDT.toDate(), timeUnit, group, type,
                        name, MetricFeature.class);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        } else {
            throw new IOException("Location uri must begin with metrics://");
        }
    }
}

From source file:org.camunda.bpm.engine.impl.calendar.DurationHelper.java

License:Apache License

private Date parseDate(String date) throws Exception {
    return DateTime.parse(date).toDate();
}

From source file:org.camunda.bpm.engine.rest.dto.converter.DateConverter.java

License:Apache License

@Override
public Date convertQueryParameterToType(String value) {
    return DateTime.parse(value).toDate();
}

From source file:org.camunda.bpm.engine.rest.helper.MockProvider.java

License:Apache License

public static Task createMockTask() {
    Task mockTask = new MockTaskBuilder().id(EXAMPLE_TASK_ID).name(EXAMPLE_TASK_NAME)
            .assignee(EXAMPLE_TASK_ASSIGNEE_NAME).createTime(DateTime.parse(EXAMPLE_TASK_CREATE_TIME).toDate())
            .dueDate(DateTime.parse(EXAMPLE_TASK_DUE_DATE).toDate())
            .delegationState(EXAMPLE_TASK_DELEGATION_STATE).description(EXAMPLE_TASK_DESCRIPTION)
            .executionId(EXAMPLE_TASK_EXECUTION_ID).owner(EXAMPLE_TASK_OWNER)
            .parentTaskId(EXAMPLE_TASK_PARENT_TASK_ID).priority(EXAMPLE_TASK_PRIORITY)
            .processDefinitionId(EXAMPLE_PROCESS_DEFINITION_ID).processInstanceId(EXAMPLE_PROCESS_INSTANCE_ID)
            .taskDefinitionKey(EXAMPLE_TASK_DEFINITION_KEY).build();
    return mockTask;
}

From source file:org.camunda.bpm.engine.rest.helper.MockProvider.java

License:Apache License

public static EventSubscription createMockEventSubscription() {
    EventSubscription mock = mock(EventSubscription.class);

    when(mock.getId()).thenReturn(EXAMPLE_EVENT_SUBSCRIPTION_ID);
    when(mock.getEventType()).thenReturn(EXAMPLE_EVENT_SUBSCRIPTION_TYPE);
    when(mock.getEventName()).thenReturn(EXAMPLE_EVENT_SUBSCRIPTION_NAME);
    when(mock.getExecutionId()).thenReturn(EXAMPLE_EXECUTION_ID);
    when(mock.getProcessInstanceId()).thenReturn(EXAMPLE_PROCESS_INSTANCE_ID);
    when(mock.getActivityId()).thenReturn(EXAMPLE_ACTIVITY_ID);
    when(mock.getCreated()).thenReturn(DateTime.parse(EXAMPLE_EVENT_SUBSCRIPTION_CREATION_DATE).toDate());

    return mock;/*  w  ww.java 2  s .co  m*/
}

From source file:org.camunda.bpm.engine.rest.helper.MockProvider.java

License:Apache License

public static HistoricActivityInstance createMockHistoricActivityInstance() {
    HistoricActivityInstance mock = mock(HistoricActivityInstance.class);

    when(mock.getId()).thenReturn(EXAMPLE_HISTORIC_ACTIVITY_INSTANCE_ID);
    when(mock.getParentActivityInstanceId())
            .thenReturn(EXAMPLE_HISTORIC_ACTIVITY_INSTANCE_PARENT_ACTIVITY_INSTANCE_ID);
    when(mock.getActivityId()).thenReturn(EXAMPLE_ACTIVITY_ID);
    when(mock.getActivityName()).thenReturn(EXAMPLE_ACTIVITY_NAME);
    when(mock.getActivityType()).thenReturn(EXAMPLE_ACTIVITY_TYPE);
    when(mock.getProcessDefinitionId()).thenReturn(EXAMPLE_PROCESS_DEFINITION_ID);
    when(mock.getProcessInstanceId()).thenReturn(EXAMPLE_PROCESS_INSTANCE_ID);
    when(mock.getExecutionId()).thenReturn(EXAMPLE_EXECUTION_ID);
    when(mock.getTaskId()).thenReturn(EXAMPLE_TASK_ID);
    when(mock.getCalledProcessInstanceId())
            .thenReturn(EXAMPLE_HISTORIC_ACTIVITY_INSTANCE_CALLED_PROCESS_INSTANCE_ID);
    when(mock.getAssignee()).thenReturn(EXAMPLE_TASK_ASSIGNEE_NAME);
    when(mock.getStartTime())/*from   www  .  j  a v  a  2  s .  c  o  m*/
            .thenReturn(DateTime.parse(EXAMPLE_HISTORIC_ACTIVITY_INSTANCE_START_TIME).toDate());
    when(mock.getEndTime()).thenReturn(DateTime.parse(EXAMPLE_HISTORIC_ACTIVITY_INSTANCE_END_TIME).toDate());
    when(mock.getDurationInMillis()).thenReturn(EXAMPLE_HISTORIC_ACTIVITY_INSTANCE_DURATION);

    return mock;
}

From source file:org.camunda.bpm.engine.rest.helper.MockProvider.java

License:Apache License

public static HistoricActivityInstance createMockRunningHistoricActivityInstance() {
    HistoricActivityInstance mock = mock(HistoricActivityInstance.class);

    when(mock.getId()).thenReturn(EXAMPLE_HISTORIC_ACTIVITY_INSTANCE_ID);
    when(mock.getParentActivityInstanceId())
            .thenReturn(EXAMPLE_HISTORIC_ACTIVITY_INSTANCE_PARENT_ACTIVITY_INSTANCE_ID);
    when(mock.getActivityId()).thenReturn(EXAMPLE_ACTIVITY_ID);
    when(mock.getActivityName()).thenReturn(EXAMPLE_ACTIVITY_NAME);
    when(mock.getActivityType()).thenReturn(EXAMPLE_ACTIVITY_TYPE);
    when(mock.getProcessDefinitionId()).thenReturn(EXAMPLE_PROCESS_DEFINITION_ID);
    when(mock.getProcessInstanceId()).thenReturn(EXAMPLE_PROCESS_INSTANCE_ID);
    when(mock.getExecutionId()).thenReturn(EXAMPLE_EXECUTION_ID);
    when(mock.getTaskId()).thenReturn(EXAMPLE_TASK_ID);
    when(mock.getCalledProcessInstanceId())
            .thenReturn(EXAMPLE_HISTORIC_ACTIVITY_INSTANCE_CALLED_PROCESS_INSTANCE_ID);
    when(mock.getAssignee()).thenReturn(EXAMPLE_TASK_ASSIGNEE_NAME);
    when(mock.getStartTime())/*from   w  w w.  j a v  a2s  .c  o  m*/
            .thenReturn(DateTime.parse(EXAMPLE_HISTORIC_ACTIVITY_INSTANCE_START_TIME).toDate());
    when(mock.getEndTime()).thenReturn(null);
    when(mock.getDurationInMillis()).thenReturn(null);

    return mock;
}