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:io.smalldata.ohmageomh.surveys.domain.ISOW3CDateTimeFormat.java

License:Apache License

/**
 * Returns a formatter that combines all ISOW3CDateTimeFormats. This
 * formatter will correctly parse any of the other formatters and will only
 * fail if the value doesn't match any of them.
 * //from  ww  w. j av a2 s. com
 * @return A universal DateTimeFormatter for all ISO W3C date-time formats.
 * 
 * @see #year()
 * @see #yearMonth()
 * @see #yearMonthDay()
 * @see #dateHourMinuteZone()
 * @see #dateHourMinuteSecondZone()
 * @see #dateHourMinuteSecondMillisZone()
 */
public static DateTimeFormatter any() {
    if (any == null) {
        any = new DateTimeFormatter(ISODateTimeFormat.dateTime().getPrinter(), new ISOW3CDateTimeParser())
                .withOffsetParsed();
    }
    return any;
}

From source file:io.spikex.filter.internal.Rule.java

License:Apache License

private static DateTime createDateTime(final JsonObject config, final String field) {

    DateTime dt;/*from w w  w  .  j a  v  a 2 s . com*/
    String dateStr = config.getString(field);
    m_logger.trace("date string: {}", dateStr);

    if (dateStr != null && dateStr.startsWith(BUILTIN_NOW)) {
        dt = Variables.createDateTimeNow(dateStr);
    } else {
        DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
        dt = fmt.parseDateTime(dateStr);
    }

    return dt;
}

From source file:io.verticle.oss.apex.service.processing.inbound.IndexCompatibleDateTimeFormatter.java

License:Apache License

public static String getIsoFormattedDateString(Date date) {

    String formatted = null;/*w  ww .  ja  v a  2 s .  com*/

    if (date != null) {
        DateTime dt = new DateTime(date);
        DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
        formatted = fmt.print(dt);
    }
    return formatted;
}

From source file:io.warp10.continuum.ThrottlingManager.java

License:Apache License

private static void dumpCurrentConfig() {
    if (null != dir && !producerHLLPEstimators.isEmpty() && !applicationHLLPEstimators.isEmpty()) {
        File config;/*from  w  w w . j  av  a 2 s  . c om*/
        if (".dump".endsWith(THROTTLING_MANAGER_SUFFIX)) {
            config = new File(dir, "current" + THROTTLING_MANAGER_SUFFIX + ".dump.");
        } else {
            config = new File(dir, "current" + THROTTLING_MANAGER_SUFFIX + ".dump");
        }

        try {
            PrintWriter pw = new PrintWriter(config);

            pw.println("###");
            pw.println("### Automatic throttling configuration dumped on "
                    + ISODateTimeFormat.dateTime().print(System.currentTimeMillis()));
            pw.println("###");

            Set<String> keys = producerHLLPEstimators.keySet();
            keys.addAll(producerRateLimiters.keySet());

            for (String key : keys) {
                pw.print(key);
                pw.print(":");
                Long limit = producerMADSLimits.get(key);
                if (null != limit) {
                    pw.print(limit);
                }
                pw.print(":");
                RateLimiter limiter = producerRateLimiters.get(key);
                if (null != limiter) {
                    pw.print(limiter.getRate());
                }
                pw.print(":");
                if (producerHLLPEstimators.containsKey(key)) {
                    pw.print(new String(OrderPreservingBase64.encode(producerHLLPEstimators.get(key).toBytes()),
                            Charsets.US_ASCII));
                }
                pw.println(":#");
            }

            keys = applicationHLLPEstimators.keySet();
            keys.addAll(applicationRateLimiters.keySet());

            for (String key : keys) {
                pw.print(APPLICATION_PREFIX_CHAR);
                pw.print(URLEncoder.encode(key, "UTF-8"));
                pw.print(":");
                Long limit = applicationMADSLimits.get(key);
                if (null != limit) {
                    pw.print(limit);
                }
                pw.print(":");
                RateLimiter limiter = applicationRateLimiters.get(key);
                if (null != limiter) {
                    pw.print(limiter.getRate());
                }
                pw.print(":");
                if (applicationHLLPEstimators.containsKey(key)) {
                    pw.print(new String(
                            OrderPreservingBase64.encode(applicationHLLPEstimators.get(key).toBytes()),
                            Charsets.US_ASCII));
                }
                pw.println(":#");
            }

            pw.close();
        } catch (Exception e) {
            LOG.error("Error while dumping throttling configuration.");
        }
    }
}

From source file:it.pronetics.madstore.crawler.publisher.impl.AtomPublisherImpl.java

License:Apache License

private void setUpdatedDateTimeIfNecessary(Element entry) {
    NodeList updatedNodes = entry.getElementsByTagName(AtomConstants.ATOM_ENTRY_UPDATED);
    Node updatedNode = updatedNodes.item(0);
    if (updatedNode != null) {
        String entryUpdatedDateTime = updatedNode.getTextContent();
        if (entryUpdatedDateTime == null || entryUpdatedDateTime.equals("")) {
            LOG.warn("The entry has no updated date, using current time ...");
            updatedNode.setTextContent(ISODateTimeFormat.dateTime().print(System.currentTimeMillis()));
        }// ww w . j a  v  a  2s.  c o  m
    } else {
        LOG.warn("The entry has no updated date, using current time ...");
        updatedNode = entry.getOwnerDocument().createElementNS(AtomConstants.ATOM_NS,
                AtomConstants.ATOM_ENTRY_UPDATED);
        updatedNode.setTextContent(ISODateTimeFormat.dateTime().print(System.currentTimeMillis()));
        entry.appendChild(updatedNode);
    }
}

From source file:jongo.demo.Demo.java

License:Open Source License

private static void generateDemoDatabase(final DatabaseConfiguration dbcfg) {
    final String database = dbcfg.getDatabase();
    QueryRunner run = new QueryRunner(JDBCConnectionFactory.getDataSource(dbcfg));

    l.info("Generating Demo resources in database {}", database);
    update(run, getCreateAuthTable());/*from w w w  .j ava 2s .c om*/
    update(run, getCreateUserTable());
    update(run, getCreateMakersTable());
    update(run, getCreateCarsTable());
    update(run, getCreateCommentsTable());
    update(run, getCreatePicturesTable());
    update(run, getCreateSalesStatsTable());
    update(run, getCreateSalesByMakerAndModelStatsTable());
    update(run, getCreateEmptyTable());

    l.info("Generating Demo Data in database {}", database);

    final String insertAuthQuery = "INSERT INTO jongo_auth (email, password) VALUES (?,?)";
    update(run, insertAuthQuery, "a@a.com", JongoUtils.getHashedPassword("123456"));
    update(run, insertAuthQuery, "a@b.com", JongoUtils.getHashedPassword("This is a test"));

    final String insertUserQuery = "INSERT INTO users (name, age, birthday, credit) VALUES (?,?,?,?)";
    update(run, insertUserQuery, "foo", 30, "1982-12-13", 32.5);
    update(run, insertUserQuery, "bar", 33, "1992-01-15", 0);

    for (CarMaker maker : CarMaker.values()) {
        update(run, "INSERT INTO maker (name, realname) VALUES (?,?)", maker.name(), maker.getRealName());
    }

    final String insertCar = "INSERT INTO car (maker, model, year, fuel, transmission, currentMarketValue, newValue) VALUES (?,?,?,?,?,?,?)";
    update(run, insertCar, "CITROEN", "C2", 2008, "Gasoline", "Manual", 9000, 13000);
    update(run,
            "INSERT INTO car (maker, model, year, transmission, currentMarketValue, newValue) VALUES (?,?,?,?,?,?)",
            "FIAT", "500", 2010, "Manual", 19000, 23.000);
    update(run, insertCar, "BMW", "X5", 2011, "Diesel", "Automatic", 59000, 77000);

    final String insertComment = "INSERT INTO comments (car_id, car_comment) VALUES (?,?)";
    update(run, insertComment, 0, "The Citroen C2 is a small car with a great attitude");
    update(run, insertComment, 0, "I Love my C2");
    update(run, insertComment, 2,
            "BMW's X5 costs too much for what it's worth. Checkout http://www.youtube.com/watch?v=Bg1TB4dRobY");

    final String insertPicture = "INSERT INTO pictures (car_id, picture) VALUES (?,?)";
    update(run, insertPicture, 0, "http://www.babez.de/citroen/c2/picth01.jpg");
    update(run, insertPicture, 0, "http://www.babez.de/citroen/c2/pic02.jpg");
    update(run, insertPicture, 0, "http://www.babez.de/citroen/c2/picth03.jpg");

    update(run, insertPicture, 1, "http://www.dwsauto.com/wp-content/uploads/2008/07/fiat-500-photo.jpg");
    update(run, insertPicture, 1, "http://www.cochesadictos.com/coches/fiat-500/imagenes/index1.jpg");
    update(run, insertPicture, 1, "http://www.cochesadictos.com/coches/fiat-500/imagenes/index4.jpg");

    update(run, insertPicture, 2, "http://www.coches21.com/fotos/100/bmw_x5_457.jpg");
    update(run, insertPicture, 2, "http://www.coches21.com/fotos/100/bmw_x5_460.jpg");
    update(run, insertPicture, 2, "http://www.coches21.com/modelos/250/bmw_x5_65.jpg");

    // generate some random data for the stats page
    DateTimeFormatter isofmt = ISODateTimeFormat.dateTime();
    DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.SSSSSSSSS");
    DateTime dt;// = isofmt.parseDateTime("2012-01-16T13:34:00.000Z");
    for (int year = 2000; year < 2012; year++) {
        for (int month = 1; month <= 12; month++) {
            int val = 1910 + new Random().nextInt(100);
            dt = isofmt.parseDateTime(year + "-" + month + "-01T01:00:00.000Z");
            update(run, "INSERT INTO sales_stats (year, month, sales, last_update) VALUES (?,?,?,?)", year,
                    month, val, fmt.print(dt));
            for (CarMaker maker : CarMaker.values()) {
                val = new Random().nextInt(100);
                update(run,
                        "INSERT INTO maker_stats (year, month, sales, maker, last_update) VALUES (?,?,?,?,?)",
                        year, month, val, maker.name(), fmt.print(dt));
            }
        }
    }

    update(run, "SET TABLE maker READONLY TRUE");

    //load the sp
    update(run, "CREATE FUNCTION simpleStoredProcedure () RETURNS TINYINT RETURN 1");
    update(run,
            "CREATE PROCEDURE insert_comment (IN car_id INTEGER, IN car_comment VARCHAR(255)) MODIFIES SQL DATA INSERT INTO comments VALUES (DEFAULT, car_id, car_comment)");
    update(run,
            "CREATE PROCEDURE get_year_sales (IN in_year INTEGER, OUT out_total INTEGER) READS SQL DATA SELECT COUNT(sales) INTO out_total FROM sales_stats WHERE year = in_year");
    update(run, getCreateView());

}

From source file:jongo.JongoUtils.java

License:Open Source License

/**
 * 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/*w w w  .ja v a  2  s .c  o  m*/
 * @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(arg + " is not a valid ISO DateTime");
    }
    return ret;
}

From source file:jongo.JongoUtils.java

License:Open Source License

/**
 * Infers the java.sql.Types of the given String and returns the JDBC mappable Object corresponding to it.
 * The conversions are like this:/* w w w. j a v a 2s.  c o m*/
 * String -> String
 * Numeric -> Integer
 * Date or Time -> Date
 * Decimal -> BigDecimal
 * ??? -> TimeStamp
 * @param val a String with the value to be mapped
 * @return a JDBC mappable object instance with the value
 */
public static Object parseValue(String val) {
    Object ret = null;
    if (!StringUtils.isWhitespace(val) && StringUtils.isNumeric(val)) {
        try {
            ret = Integer.valueOf(val);
        } catch (Exception e) {
            l.debug(e.getMessage());
        }
    } else {
        DateTime date = JongoUtils.isDateTime(val);
        if (date != null) {
            l.debug("Got a DateTime " + date.toString(ISODateTimeFormat.dateTime()));
            ret = new java.sql.Timestamp(date.getMillis());
        } else {
            date = JongoUtils.isDate(val);
            if (date != null) {
                l.debug("Got a Date " + date.toString(ISODateTimeFormat.date()));
                ret = new java.sql.Date(date.getMillis());
            } else {
                date = JongoUtils.isTime(val);
                if (date != null) {
                    l.debug("Got a Time " + date.toString(ISODateTimeFormat.time()));
                    ret = new java.sql.Time(date.getMillis());
                }
            }
        }

        if (ret == null && val != null) {
            l.debug("Not a datetime. Try someting else. ");
            try {
                ret = new BigDecimal(val);
            } catch (NumberFormatException e) {
                l.debug(e.getMessage());
                ret = val;
            }
        }
    }
    return ret;
}

From source file:jongo.JongoUtils.java

License:Open Source License

/**
 * The date and time that the message was sent
 * @return The date and time that the message was sent
 *//*from www. j a  va 2s. c o  m*/
public static String getDateHeader() {
    return new DateTime().toString(ISODateTimeFormat.dateTime());
}

From source file:me.vertretungsplan.parser.DSBMobileParser.java

License:Mozilla Public License

private JSONObject getDataFromApi(String login, String password)
        throws JSONException, IOException, CredentialInvalidException {
    JSONObject json = new JSONObject();
    json.put("AppId", "");
    json.put("PushId", "");
    json.put("UserId", login);
    json.put("UserPw", password);
    json.put("AppVersion", "0.8");
    json.put("Device", "WebApp");
    json.put("OsVersion",
            "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36");
    json.put("Language", "de");
    json.put("Date", ISODateTimeFormat.dateTime().print(DateTime.now()));
    json.put("LastUpdate", ISODateTimeFormat.dateTime().print(DateTime.now()));
    json.put("BundleId", "de.heinekingmedia.inhouse.dsbmobile.web");
    JSONObject payload = new JSONObject();
    JSONObject req = new JSONObject();
    req.put("Data", encode(json.toString()));
    req.put("DataType", 1);
    payload.put("req", req);

    JSONObject responseJson = new JSONObject(
            httpPost(URL, ENCODING, payload.toString(), ContentType.APPLICATION_JSON));
    String data = decode(responseJson.getString("d"));
    return new JSONObject(data);
}