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:me.vertretungsplan.parser.WebUntisParser.java

License:Mozilla Public License

private Object request(String method, @NotNull JSONObject params, boolean internal)
        throws JSONException, IOException, CredentialInvalidException, UnauthorizedException {
    String host = data.getString(PARAM_HOST);
    String school = data.getString(PARAM_SCHOOLNAME);

    final String protocol = data.optString(PARAM_PROTOCOL, "https") + "://";
    String url = protocol + host + "/WebUntis/jsonrpc" + (internal ? "_intern" : "") + ".do?school="
            + URLEncoder.encode(school, "UTF-8");

    Map<String, String> headers = new HashMap<>();
    headers.put("User-Agent", USERAGENT);

    if (internal && !method.equals("getAppSharedSecret")) {
        JSONObject auth = new JSONObject();
        long time = System.currentTimeMillis();
        auth.put("user", ((UserPasswordCredential) credential).getUsername());
        try {//from w  ww  . ja v a  2  s  .c o  m
            auth.put("otp", authCodeInternal(time));
        } catch (NoSuchAlgorithmException | InvalidKeyException e) {
            throw new IOException(e);
        }
        auth.put("clientTime", time);
        params.put("auth", auth);
    }

    JSONObject body = new JSONObject();
    body.put("id", ISODateTimeFormat.dateTime().print(DateTime.now()));
    body.put("method", method);
    if (internal) {
        JSONArray paramsArray = new JSONArray();
        paramsArray.put(params);
        body.put("params", paramsArray);
    } else {
        body.put("params", params);
    }
    body.put("jsonrpc", "2.0");

    JSONObject response = new JSONObject(
            httpPost(url, "UTF-8", body.toString(), ContentType.APPLICATION_JSON, headers));
    if (!response.getString("id").equals(body.getString("id"))) {
        throw new IOException("wrong id returned by API");
    } else if (!response.has("result")) {
        JSONObject error = response.getJSONObject("error");
        switch (error.getInt("code")) {
        case -32601:
            throw new IOException("Method not found");
        case -8504: // wrong password
        case -8998: // user temporarily blocked
        case -8502: // no username specified
            throw new CredentialInvalidException();
        case -8520:
            throw new IOException("not logged in");
        case -8509:
            throw new UnauthorizedException();
        default:
            throw new IOException(error.toString());
        }
    }
    return response.get("result");
}

From source file:monasca.api.infrastructure.persistence.influxdb.InfluxV9Utils.java

License:Apache License

String buildTimePart(final DateTime startTime, final DateTime endTime) {
    final StringBuilder sb = new StringBuilder();

    if (startTime != null) {
        sb.append(String.format(" and time > " + "'" + ISODateTimeFormat.dateTime().print(startTime) + "'"));
    }/*from  w  w w .  j av a2  s.c om*/

    if (endTime != null) {
        sb.append(String.format(" and time < " + "'" + ISODateTimeFormat.dateTime().print(endTime) + "'"));
    }

    return sb.toString();
}

From source file:monasca.api.infrastructure.persistence.influxdb.InfluxV9Utils.java

License:Apache License

public String timeOffsetPart(String offset) {

    if (StringUtils.isEmpty(offset)) {
        return StringUtils.EMPTY;
    }/* w  w  w . j a  va  2  s.  co m*/
    if (!"0".equals(offset)) {
        Object convertible;
        try {
            convertible = Long.valueOf(offset);
        } catch (IllegalArgumentException exp) {
            // not a numeric value
            convertible = offset;
        }
        offset = Conversions.variantToDateTime(convertible).toString(ISODateTimeFormat.dateTime());
    }

    return String.format(" and time > '%1$s'", offset);
}

From source file:monasca.api.infrastructure.persistence.influxdb.InfluxV9Utils.java

License:Apache License

public String startTimePart(DateTime startTime) {

    return startTime != null ? " and time > " + "'" + ISODateTimeFormat.dateTime().print(startTime) + "'" : "";
}

From source file:monasca.api.infrastructure.persistence.influxdb.InfluxV9Utils.java

License:Apache License

public String endTimePart(DateTime endTime) {

    return endTime != null ? " and time < " + "'" + ISODateTimeFormat.dateTime().print(endTime) + "'" : "";
}

From source file:monasca.persister.repository.influxdb.Measurement.java

License:Apache License

public String getISOFormattedTimeString() {

    DateTimeFormatter dateFormatter = ISODateTimeFormat.dateTime();
    Date date = new Date(this.time);
    DateTime dateTime = new DateTime(date.getTime(), DateTimeZone.UTC);

    return dateFormatter.print(dateTime);
}

From source file:net.form105.rm.base.model.parameter.TimestampParameter.java

License:Apache License

@Override
public String getValueAsString() {
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    return fmt.print(dateTime);
}

From source file:net.nicholaswilliams.java.teamcity.plugin.buildNumber.PluginConfigurationServiceDefault.java

License:Apache License

protected void saveConfiguration() throws IOException {
    PluginConfigurationServiceDefault.logger.info("Saving the plugin configuration to the XML file.");

    this.configFileWatcher.stop();

    this.configuration.setLastUpdate(new DateTime());

    List<String> lines = new ArrayList<String>(this.configFileHeader);
    lines.add("");

    lines.add("\t<last-update>" + ISODateTimeFormat.dateTime().print(this.configuration.getLastUpdate())
            + "</last-update>");
    lines.add("");

    this.writeSettings(lines);

    this.writeBuildNumbers(lines);

    lines.add("</shared-build-number-config>");
    lines.add("");

    try {//  ww w  . j a  v a 2 s . c o m
        FileUtils.writeLines(this.configFile, lines);
    } finally {
        this.initializeFileWatcher();
    }
}

From source file:net.simonvt.cathode.api.util.TimeUtils.java

License:Apache License

public static long getMillis(String iso) {
    if (iso != null) {
        final int length = iso.length();
        DateTimeFormatter fmt;//from  ww w.j a  va2 s . com

        if (length <= 20) {
            fmt = ISODateTimeFormat.dateTimeNoMillis();
        } else {
            fmt = ISODateTimeFormat.dateTime();
        }

        return fmt.parseDateTime(iso).getMillis();
    }

    return 0L;
}

From source file:net.simonvt.cathode.api.util.TimeUtils.java

License:Apache License

public static String getIsoTime() {
    DateTime dt = new DateTime();
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime().withZoneUTC();
    return fmt.print(dt);
}