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.jevis.structurecreator.JSON2JEVisStructureCreator.java

License:Open Source License

private void deleteOldSamples(JEVisObject jevisObject) throws JEVisException {
    try {//from w ww.j  a  v  a 2  s .  c om
        String objName = jevisObject.getName();
        String className = jevisObject.getJEVisClass().getName();
        System.out.println(
                String.format("Delete old Samples from Object 'obj/class': '%s/%s'", objName, className));
    } catch (NullPointerException e) {
    }
    for (JEVisAttribute att : jevisObject.getAttributes()) {
        JEVisSample latestSample = att.getLatestSample();
        latestSample.getTimestamp();
        att.deleteSamplesBetween(DateTime.parse("0"), latestSample.getTimestamp().minus(1));
    }
}

From source file:org.jraf.irondad.handler.countdown.CountDownHandler.java

License:Open Source License

private String getReply(String eventDateStr) {
    DateTime eventDateTime = DateTime.parse(eventDateStr);
    DateTime nowDateTime = DateTime.now();

    String res = null;//  w  w w .  j  av a  2 s .c  o m

    int nbDays = Days.daysBetween(nowDateTime.toLocalDateTime().toDateTime().withTimeAtStartOfDay(),
            eventDateTime.toLocalDateTime().toDateTime().withTimeAtStartOfDay()).getDays();
    if (nbDays > 2) {
        res = "Dans " + nbDays + " jours !";
    } else if (nbDays == 2) {
        res = "APRS-DEMAIN !!!";
    } else if (nbDays == 1) {
        res = "DEMAIN !!!!!!";
    } else if (nbDays == 0) {
        int nbHours = Hours.hoursBetween(nowDateTime, eventDateTime).getHours();
        if (nbHours > 0) {
            if (nbHours == 1)
                res = "Dans " + nbHours + " heure (et quelques) !!";
            else
                res = "Dans " + nbHours + " heures (et quelques) !";
        } else if (nbHours < 0) {
            res = "C'est en ce moment.";
        } else {
            int nbMinutes = Minutes.minutesBetween(nowDateTime, eventDateTime).getMinutes();
            if (nbMinutes > 0) {
                if (nbMinutes == 1)
                    res = "Dans 1 minute !!!";
                else
                    res = "Dans " + nbMinutes + " minutes !!";
            } else if (nbMinutes < 0) {
                res = "C'est en ce moment mme !!!!!";
            } else {
                int nbSeconds = Seconds.secondsBetween(nowDateTime, eventDateTime).getSeconds();
                if (nbSeconds > 0)
                    res = "Dans " + nbSeconds + " secondes !!!!";
                else if (nbSeconds < 0)
                    res = "a commence !!!!!";
                else
                    res = "C'est commenc !!!!!";
            }
        }
    } else if (nbDays == -1) {
        res = "C'est en ce moment...";
    } else {
        res = "C'est fini :(";
    }
    return res;
}

From source file:org.kuali.kpme.core.role.proxy.service.KpmeRoleProxyDerivedRoleTypeServiceImpl.java

License:Educational Community License

@Override
public List<RoleMembership> getRoleMembersFromDerivedRole(String namespaceCode, String roleName,
        Map<String, String> qualification) {
    List<RoleMembership> returnList = new ArrayList<RoleMembership>();

    // get the as-of date and the active flag values
    DateTime asOfDate = LocalDate.now().toDateTimeAtStartOfDay();
    String asOfDateString = qualification.remove(KPME_PROXIED_ROLE_AS_OF_DATE);
    if (asOfDateString != null) {
        asOfDate = DateTime.parse(asOfDateString);
    }//  w  w w .j  a va 2s  .  c  om

    boolean activeOnly = true;
    String activeOnlyString = qualification.remove(KPME_PROXIED_ROLE_IS_ACTIVE_ONLY);
    if (activeOnlyString != null) {
        activeOnly = Boolean.parseBoolean(activeOnlyString);
    }

    String proxiedRoleNamespaceCode = qualification.remove(KPME_PROXIED_ROLE_NAMESPACE_CODE);
    if (proxiedRoleNamespaceCode == null) {
        // use the hook to get the namespace
        proxiedRoleNamespaceCode = this.getProxiedRoleNamespaceCode();
    }

    String proxiedRoleName = qualification.remove(KPME_PROXIED_ROLE_ROLE_NAME);
    if (proxiedRoleName == null) {
        // use the hook to get the role name
        proxiedRoleName = this.getProxiedRoleName();
    }

    // check that the role is valid and if so invoke the (caching) logic for querying the proxied role membership
    if (getRoleService().getRoleByNamespaceCodeAndName(proxiedRoleNamespaceCode, proxiedRoleName) != null) {
        returnList = convertToRoleMemberships(getRoleMembersCached(proxiedRoleNamespaceCode, proxiedRoleName,
                qualification, asOfDate, activeOnly));
    } else {
        LOG.error("Role instance for proxied role with name " + proxiedRoleName + " namespace "
                + proxiedRoleNamespaceCode + " was null");
    }

    return returnList;
}

From source file:org.kuali.kpme.core.role.proxy.service.KpmeRoleProxyDerivedRoleTypeServiceImpl.java

License:Educational Community License

@Override
public boolean hasDerivedRole(String principalId, List<String> groupIds, String namespaceCode, String roleName,
        Map<String, String> qualification) {
    boolean retVal = false;

    String proxiedRoleNamespaceCode = qualification.remove(KPME_PROXIED_ROLE_NAMESPACE_CODE);
    if (proxiedRoleNamespaceCode == null) {
        // use the hook to get the namespace
        proxiedRoleNamespaceCode = this.getProxiedRoleNamespaceCode();
    }//  w  w  w.  j  a va  2 s  .c  om

    String proxiedRoleName = qualification.remove(KPME_PROXIED_ROLE_ROLE_NAME);
    if (proxiedRoleName == null) {
        // use the hook to get the role name
        proxiedRoleName = this.getProxiedRoleName();
    }

    // get the as-of date and the active flag values
    DateTime asOfDate = LocalDate.now().toDateTimeAtStartOfDay();
    String asOfDateString = qualification.remove(KPME_PROXIED_ROLE_AS_OF_DATE);
    if (asOfDateString != null) {
        asOfDate = DateTime.parse(asOfDateString);
    }

    boolean activeOnly = true;
    String activeOnlyString = qualification.remove(KPME_PROXIED_ROLE_IS_ACTIVE_ONLY);
    if (activeOnlyString != null) {
        activeOnly = Boolean.parseBoolean(activeOnlyString);
    }

    Role proxiedRole = getRoleService().getRoleByNamespaceCodeAndName(proxiedRoleNamespaceCode,
            proxiedRoleName);

    if (proxiedRole != null) {
        if ((asOfDate.toLocalDate().toDateTimeAtStartOfDay().equals(LocalDate.now().toDateTimeAtStartOfDay()))
                && activeOnly) {
            // invoke the non-recursive helper that delegates to KIM
            retVal = isActiveMemberOfRoleToday(principalId, groupIds, proxiedRole, qualification);
        } else {
            // invoke the recursive helper
            retVal = isMemberOfRole(principalId, proxiedRole, qualification, asOfDate, activeOnly);
        }
    } else {
        LOG.error("Role for role name " + proxiedRoleName + " with namespace code " + proxiedRoleNamespaceCode
                + " was null");
    }

    return retVal;
}

From source file:org.labs.qbit.location.utils.DateUtil.java

License:Open Source License

/**
 * Create joda's date time object with the given string expression
 *
 * @param dateExpression/*from w  w w . j a v  a  2  s . c  o m*/
 *            date expression string
 * @param defaultDateTime
 *            DateTime
 * @return Datetime
 */
public static DateTime dateTimeFromString(String dateExpression, DateTime defaultDateTime) {
    LocationLogger.debug(DateUtil.class,
            "Creating datetime from String expression [{}], with default datetime [{}]", dateExpression,
            defaultDateTime);
    try {
        return dateExpression == null ? defaultDateTime : DateTime.parse(dateExpression);
    } catch (IllegalArgumentException ex) {
        throw new LocationException(LocationErrorBox.dateBuildErrorCode, ex.getMessage(), ex);
    }
}

From source file:org.megam.deccanplato.provider.salesforce.crm.handler.OpportunitiesImpl.java

License:Open Source License

/**
 * this method creates an opportunity in salesforce.com and returns that opportunity id.
 * This method gets input from a MAP(contains json data) and returns a MAp.
 * @param outMap /*from  w w  w  .j a  va  2s  . c  om*/
 */
private Map<String, String> create() {
    final String SALESFORCE_CREATE_OPPORTUNITY_URL = args.get(INSTANCE_URL) + SALESFORCE_OPPORTUNITY_URL;
    Map<String, String> outMap = new HashMap<>();
    Map<String, String> header = new HashMap<String, String>();
    header.put(S_AUTHORIZATION, S_OAUTH + args.get(ACCESS_TOKEN));
    Map<String, Object> userAttrMap = new HashMap<String, Object>();
    userAttrMap.put(S_NAME, args.get(NAME));
    userAttrMap.put(S_STAGENAME, args.get(STAGE_NAME));
    userAttrMap.put(S_CLOSEDATE, DateTime.parse(args.get(CLOSE_DATE)));

    GsonBuilder gson = new GsonBuilder();
    gson.registerTypeAdapter(DateTime.class, new DateTimeTypeConverter());
    Gson obj = gson.setPrettyPrinting().create();
    TransportTools tst = new TransportTools(SALESFORCE_CREATE_OPPORTUNITY_URL, null, header);
    tst.setContentType(ContentType.APPLICATION_JSON, obj.toJson(userAttrMap));
    try {
        String responseBody = TransportMachinery.post(tst).entityToString();
        outMap.put(OUTPUT, responseBody);
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return outMap;
}

From source file:org.n52.io.extension.resulttime.ResultTimeRepository.java

License:Open Source License

protected String parseToIso(String input) {
    return DateTime.parse(input).toString();
}

From source file:org.n52.io.IntervalWithTimeZone.java

License:Open Source License

public DateTimeZone getTimezone() {
    String endTime = timespan.split("/")[1];
    return DateTime.parse(endTime).getZone();
}

From source file:org.n52.io.measurement.img.ChartIoHandler.java

License:Open Source License

private XYPlot createChart(IoStyleContext context) {
    DateTime end = getTimespan() != null ? DateTime.parse(getTimespan().split("/")[1]) : new DateTime();
    //DateTime end = DateTime.parse(getTimespan().split("/")[1]);
    String zoneName = end.getZone().getShortName(end.getMillis(), i18n.getLocale());
    zoneName = "+00:00".equalsIgnoreCase(zoneName) ? "UTC" : zoneName;

    StringBuilder domainAxisLabel = new StringBuilder(i18n.get("msg.io.chart.time"));
    domainAxisLabel.append(" (").append(zoneName).append(")");
    boolean showLegend = getChartStyleDefinitions().isLegend();
    chart = createTimeSeriesChart(null, domainAxisLabel.toString(), i18n.get("msg.io.chart.value"), null,
            showLegend, false, true);/*from w  w w.  j a va2 s  .co  m*/
    return createPlotArea(chart);
}

From source file:org.n52.movingcode.runtime.codepackage.PID.java

License:Apache License

/**
 * Parses a packageId of the form/*  ww  w.j ava  2s  .c om*/
 * my.package.name(version-timestamp)
 * 
 * 
 * @param s
 * @return
 */
public static final PID fromString(String s) {
    int versionStart = s.lastIndexOf("_");
    String name = s.substring(0, versionStart);
    DateTime timestamp = DateTime.parse(s.substring(versionStart + 1, s.length()));
    return new PID(name, timestamp);
}