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

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

Introduction

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

Prototype

public static DateTimeFormatter dateTimeNoMillis() 

Source Link

Document

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

Usage

From source file:org.elasticsearch.common.xcontent.BaseXContentTestCase.java

License:Apache License

public void testDate() throws Exception {
    assertResult("{'date':null}", () -> builder().startObject().field("date", (Date) null).endObject());
    assertResult("{'date':null}", () -> builder().startObject().field("date").value((Date) null).endObject());

    final Date d1 = new DateTime(2016, 1, 1, 0, 0, DateTimeZone.UTC).toDate();
    assertResult("{'d1':'2016-01-01T00:00:00.000Z'}",
            () -> builder().startObject().field("d1", d1).endObject());
    assertResult("{'d1':'2016-01-01T00:00:00.000Z'}",
            () -> builder().startObject().field("d1").value(d1).endObject());

    final Date d2 = new DateTime(2016, 12, 25, 7, 59, 42, 213, DateTimeZone.UTC).toDate();
    assertResult("{'d2':'2016-12-25T07:59:42.213Z'}",
            () -> builder().startObject().field("d2", d2).endObject());
    assertResult("{'d2':'2016-12-25T07:59:42.213Z'}",
            () -> builder().startObject().field("d2").value(d2).endObject());

    final DateTimeFormatter formatter = randomFrom(ISODateTimeFormat.basicDate(),
            ISODateTimeFormat.dateTimeNoMillis());
    final Date d3 = DateTime.now().toDate();

    String expected = "{'d3':'" + formatter.print(d3.getTime()) + "'}";
    assertResult(expected, () -> builder().startObject().field("d3", d3, formatter).endObject());
    assertResult(expected, () -> builder().startObject().field("d3").value(d3, formatter).endObject());

    expectNonNullFormatterException(() -> builder().startObject().field("d3", d3, null).endObject());
    expectNonNullFormatterException(() -> builder().startObject().field("d3").value(d3, null).endObject());
    expectNonNullFormatterException(() -> builder().value(null, 1L));
}

From source file:org.elasticsearch.util.joda.Joda.java

License:Apache License

/**
 * Parses a joda based pattern, including some named ones (similar to the built in Joda ISO ones).
 *//* w w  w.  jav  a 2 s . c o  m*/
public static FormatDateTimeFormatter forPattern(String input) {
    DateTimeFormatter formatter;
    if ("basicDate".equals(input) || "basic_date".equals(input)) {
        formatter = ISODateTimeFormat.basicDate();
    } else if ("basicDateTime".equals(input) || "basic_date_time".equals(input)) {
        formatter = ISODateTimeFormat.basicDateTime();
    } else if ("basicDateTimeNoMillis".equals(input) || "basic_date_time_no_millis".equals(input)) {
        formatter = ISODateTimeFormat.basicDateTimeNoMillis();
    } else if ("basicOrdinalDate".equals(input) || "basic_ordinal_date".equals(input)) {
        formatter = ISODateTimeFormat.basicOrdinalDate();
    } else if ("basicOrdinalDateTime".equals(input) || "basic_ordinal_date_time".equals(input)) {
        formatter = ISODateTimeFormat.basicOrdinalDateTime();
    } else if ("basicOrdinalDateTimeNoMillis".equals(input)
            || "basic_ordinal_date_time_no_millis".equals(input)) {
        formatter = ISODateTimeFormat.basicOrdinalDateTimeNoMillis();
    } else if ("basicTime".equals(input) || "basic_time".equals(input)) {
        formatter = ISODateTimeFormat.basicTime();
    } else if ("basicTimeNoMillis".equals(input) || "basic_time_no_millis".equals(input)) {
        formatter = ISODateTimeFormat.basicTimeNoMillis();
    } else if ("basicTTime".equals(input) || "basic_t_Time".equals(input)) {
        formatter = ISODateTimeFormat.basicTTime();
    } else if ("basicTTimeNoMillis".equals(input) || "basic_t_time_no_millis".equals(input)) {
        formatter = ISODateTimeFormat.basicTTimeNoMillis();
    } else if ("basicWeekDate".equals(input) || "basic_week_date".equals(input)) {
        formatter = ISODateTimeFormat.basicWeekDate();
    } else if ("basicWeekDateTime".equals(input) || "basic_week_date_time".equals(input)) {
        formatter = ISODateTimeFormat.basicWeekDateTime();
    } else if ("basicWeekDateTimeNoMillis".equals(input) || "basic_week_date_time_no_millis".equals(input)) {
        formatter = ISODateTimeFormat.basicWeekDateTimeNoMillis();
    } else if ("date".equals(input)) {
        formatter = ISODateTimeFormat.date();
    } else if ("dateHour".equals(input) || "date_hour".equals(input)) {
        formatter = ISODateTimeFormat.dateHour();
    } else if ("dateHourMinute".equals(input) || "date_hour_minute".equals(input)) {
        formatter = ISODateTimeFormat.dateHourMinute();
    } else if ("dateHourMinuteSecond".equals(input) || "date_hour_minute_second".equals(input)) {
        formatter = ISODateTimeFormat.dateHourMinuteSecond();
    } else if ("dateHourMinuteSecondFraction".equals(input)
            || "date_hour_minute_second_fraction".equals(input)) {
        formatter = ISODateTimeFormat.dateHourMinuteSecondFraction();
    } else if ("dateHourMinuteSecondMillis".equals(input) || "date_hour_minute_second_millis".equals(input)) {
        formatter = ISODateTimeFormat.dateHourMinuteSecondMillis();
    } else if ("dateOptionalTime".equals(input) || "date_optional_time".equals(input)) {
        // in this case, we have a separate parser and printer since the dataOptionalTimeParser can't print
        return new FormatDateTimeFormatter(input,
                ISODateTimeFormat.dateOptionalTimeParser().withZone(DateTimeZone.UTC),
                ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC));
    } else if ("dateTime".equals(input) || "date_time".equals(input)) {
        formatter = ISODateTimeFormat.dateTime();
    } else if ("dateTimeNoMillis".equals(input) || "date_time_no_millis".equals(input)) {
        formatter = ISODateTimeFormat.dateTimeNoMillis();
    } else if ("hour".equals(input)) {
        formatter = ISODateTimeFormat.hour();
    } else if ("hourMinute".equals(input) || "hour_minute".equals(input)) {
        formatter = ISODateTimeFormat.hourMinute();
    } else if ("hourMinuteSecond".equals(input) || "hour_minute_second".equals(input)) {
        formatter = ISODateTimeFormat.hourMinuteSecond();
    } else if ("hourMinuteSecondFraction".equals(input) || "hour_minute_second_fraction".equals(input)) {
        formatter = ISODateTimeFormat.hourMinuteSecondFraction();
    } else if ("hourMinuteSecondMillis".equals(input) || "hour_minute_second_millis".equals(input)) {
        formatter = ISODateTimeFormat.hourMinuteSecondMillis();
    } else if ("ordinalDate".equals(input) || "ordinal_date".equals(input)) {
        formatter = ISODateTimeFormat.ordinalDate();
    } else if ("ordinalDateTime".equals(input) || "ordinal_date_time".equals(input)) {
        formatter = ISODateTimeFormat.ordinalDateTime();
    } else if ("ordinalDateTimeNoMillis".equals(input) || "ordinal_date_time_no_millis".equals(input)) {
        formatter = ISODateTimeFormat.ordinalDateTimeNoMillis();
    } else if ("time".equals(input)) {
        formatter = ISODateTimeFormat.time();
    } else if ("tTime".equals(input) || "t_time".equals(input)) {
        formatter = ISODateTimeFormat.tTime();
    } else if ("tTimeNoMillis".equals(input) || "t_time_no_millis".equals(input)) {
        formatter = ISODateTimeFormat.tTimeNoMillis();
    } else if ("weekDate".equals(input) || "week_date".equals(input)) {
        formatter = ISODateTimeFormat.weekDate();
    } else if ("weekDateTime".equals(input) || "week_date_time".equals(input)) {
        formatter = ISODateTimeFormat.weekDateTime();
    } else if ("weekyear".equals(input) || "week_year".equals(input)) {
        formatter = ISODateTimeFormat.weekyear();
    } else if ("weekyearWeek".equals(input)) {
        formatter = ISODateTimeFormat.weekyearWeek();
    } else if ("year".equals(input)) {
        formatter = ISODateTimeFormat.year();
    } else if ("yearMonth".equals(input) || "year_month".equals(input)) {
        formatter = ISODateTimeFormat.yearMonth();
    } else if ("yearMonthDay".equals(input) || "year_month_day".equals(input)) {
        formatter = ISODateTimeFormat.yearMonthDay();
    } else {
        formatter = DateTimeFormat.forPattern(input);
    }
    formatter.withZone(DateTimeZone.UTC);
    return new FormatDateTimeFormatter(input, formatter);
}

From source file:org.envirocar.server.core.guice.CoreModule.java

License:Open Source License

@Provides
@Singleton
public DateTimeFormatter formatter() {
    return ISODateTimeFormat.dateTimeNoMillis();
}

From source file:org.footware.server.gpx.GPXImport.java

License:Apache License

private List<GPXTrack> parseXML(File file) {
    LinkedList<GPXTrack> tracks = new LinkedList<GPXTrack>();
    try {//from w ww . ja v a 2 s.com
        long startTime = System.currentTimeMillis();
        logger.info("Start parsing @" + startTime);

        // Determine GPX Version
        SAXReader xmlReader = new SAXReader();
        Document document = xmlReader.read(file);
        String version = document.getRootElement().attributeValue("version");

        File xsd = null;

        if (version.equals("1.1")) {
            logger.info("Detected gpx version " + version + "  +" + (System.currentTimeMillis() - startTime));
            xsd = new File("gpx_1_1.xsd");
            GPX_NAMESPACE_URI = GPX_NAMESPACE_URI_1_1;
        } else if (version.equals("1.0")) {
            logger.info("Detected gpx version '" + version + "'  +" + (System.currentTimeMillis() - startTime));
            xsd = new File("gpx_1_0.xsd");
            GPX_NAMESPACE_URI = GPX_NAMESPACE_URI_1_0;
        } else {
            logger.info("No supported version detected: " + version + "  +"
                    + (System.currentTimeMillis() - startTime));
            // As default we try version 1.1
            xsd = new File("gpx_1_1.xsd");
            GPX_NAMESPACE_URI = GPX_NAMESPACE_URI_1_1;
        }

        // Parse GPX
        SAXParserFactory factory = SAXParserFactory.newInstance();
        SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");

        factory.setSchema(schemaFactory.newSchema(xsd));

        SAXParser parser = factory.newSAXParser();
        SAXReader reader = new SAXReader(parser.getXMLReader());
        reader.setValidation(true);
        reader.setErrorHandler(new SimpleErrorHandler());

        document = reader.read(file);
        logger.info("End parsing +" + (System.currentTimeMillis() - startTime));

        // Define namespaces
        HashMap<String, String> namespacesMap = new HashMap<String, String>();
        namespacesMap.put(GPX_NS, GPX_NAMESPACE_URI);

        // Find tracks
        logger.info("Search tracks +" + (System.currentTimeMillis() - startTime));
        XPath xpathTrk = DocumentHelper.createXPath("//" + GPX_NS + ":trk");
        xpathTrk.setNamespaceURIs(namespacesMap);

        List<Element> xmlTracks = xpathTrk.selectNodes(document);
        logger.info("Found " + xmlTracks.size() + " tracks +" + (System.currentTimeMillis() - startTime));

        GPXTrack track;

        // for (Element xmlTrack : xmlTracks) {
        // Iterate about all tracks of the gpx file
        for (int currentTrackNummer = 1; currentTrackNummer <= xmlTracks.size(); currentTrackNummer++) {
            logger.info("Start track " + currentTrackNummer + " +" + (System.currentTimeMillis() - startTime));

            track = new GPXTrack();

            // Find track segments
            XPath xpathTrkseg = DocumentHelper
                    .createXPath("//" + GPX_NS + ":trk[" + currentTrackNummer + "]/" + GPX_NS + ":trkseg");
            xpathTrkseg.setNamespaceURIs(namespacesMap);

            List<Element> xmlTrackSegs = xpathTrkseg.selectNodes(document);
            logger.info("Found " + xmlTrackSegs.size() + " segments for track " + currentTrackNummer + " +"
                    + (System.currentTimeMillis() - startTime));

            // List<Element> xmlTrackSegs =
            // xmlTrack.selectNodes("//trkseg");

            GPXTrackSegment trackSegment;

            // for (Element xmlTrackSeq : xmlTrackSegs) {
            // Iterate above all segments of a track
            for (int currentTrackSegmentNummer = 1; currentTrackSegmentNummer <= xmlTrackSegs
                    .size(); currentTrackSegmentNummer++) {
                trackSegment = new GPXTrackSegment();

                // Find track points
                XPath xpathTrkPt = DocumentHelper.createXPath("//" + GPX_NS + ":trk[" + currentTrackNummer
                        + "]/" + GPX_NS + ":trkseg[" + currentTrackSegmentNummer + "]/" + GPX_NS + ":trkpt");
                xpathTrkPt.setNamespaceURIs(namespacesMap);
                List<Element> xmlTrackPts = xpathTrkPt.selectNodes(document);

                logger.info("Found " + xmlTrackPts.size() + " points for segment " + currentTrackSegmentNummer
                        + " for track " + currentTrackNummer + " +" + (System.currentTimeMillis() - startTime));

                GPXTrackPoint trackPoint;
                BigDecimal latitude;
                BigDecimal longitude;
                BigDecimal elevation;
                DateTime time;

                // Iterate above all points of a segment of a track
                for (Element xmlTrackPt : xmlTrackPts) {

                    latitude = new BigDecimal(xmlTrackPt.attributeValue(LATITUDE));
                    longitude = new BigDecimal(xmlTrackPt.attributeValue(LONGITUDE));
                    elevation = new BigDecimal(xmlTrackPt.element(ELEVATION).getText());
                    time = ISODateTimeFormat.dateTimeNoMillis()
                            .parseDateTime(xmlTrackPt.element(TIME).getText());

                    trackPoint = new GPXTrackPoint(latitude, longitude, elevation, time);
                    trackSegment.addPoint(trackPoint);
                }
                track.addTrackSegment(trackSegment);
            }
            tracks.add(track);

        }
        logger.info("Done parsing +" + (System.currentTimeMillis() - startTime));

    } catch (ParserConfigurationException e) {
        logger.error("ParserConfigurationException", e);
        e.printStackTrace();
    } catch (SAXException e) {
        logger.error("SAXException", e);
        e.printStackTrace();
    } catch (DocumentException e) {
        logger.error("DocumentException", e);
        e.printStackTrace();
    }

    return tracks;
}

From source file:org.jbpm.process.core.timer.DateTimeUtils.java

License:Apache License

public static long parseDateTime(String dateTimeStr) {
    DateTime dt = ISODateTimeFormat.dateTimeNoMillis().parseDateTime(dateTimeStr);
    return dt.getMillis();
}

From source file:org.killbill.billing.plugin.moneris.MonerisPaymentTransactionInfoPlugin.java

License:Apache License

@Override
public DateTime getEffectiveDate() {
    // TODO Timezone? Assume UTC?
    return DateTime.parse(getTransDate() + 'T' + getTransTime() + 'Z', ISODateTimeFormat.dateTimeNoMillis());
}

From source file:org.kuali.kpme.tklm.time.detail.web.ActionFormUtils.java

License:Educational Community License

/**
 * This method will build the JSON data structure needed for calendar
 * manipulation and processing on the client side. Start and End times here
 * are based on the pre-timezone adjusted times startDisplayTime, and
 * endDisplayTime./*from w  ww. j  a  v a  2 s  .  com*/
 *
 * @param timeBlocks
 * @return
 */
public static String getTimeBlocksJson(List<TimeBlock> timeBlocks) {

    if (timeBlocks == null || timeBlocks.size() == 0) {
        return "";
    }

    List<Map<String, Object>> timeBlockList = new LinkedList<Map<String, Object>>();
    String timezone = HrServiceLocator.getTimezoneService().getUserTimezone();

    for (TimeBlock timeBlock : timeBlocks) {
        Map<String, Object> timeBlockMap = new LinkedHashMap<String, Object>();

        WorkArea workArea = HrServiceLocator.getWorkAreaService().getWorkArea(timeBlock.getWorkArea(),
                timeBlock.getEndDateTime().toLocalDate());
        String workAreaDesc = workArea.getDescription();

        String principalId = GlobalVariables.getUserSession().getPrincipalId();

        boolean isAnyApprover = HrServiceLocator.getKPMERoleService().principalHasRole(principalId,
                KPMENamespace.KPME_HR.getNamespaceCode(), KPMERole.APPROVER.getRoleName(), new DateTime())
                || HrServiceLocator.getKPMERoleService().principalHasRole(principalId,
                        KPMENamespace.KPME_HR.getNamespaceCode(), KPMERole.APPROVER_DELEGATE.getRoleName(),
                        new DateTime());
        timeBlockMap.put("isApprover", isAnyApprover);
        timeBlockMap.put("isSynchronousUser", timeBlock.getClockLogCreated());

        timeBlockMap.put("canEditTb",
                TkServiceLocator.getTKPermissionService().canEditTimeBlock(principalId, timeBlock));
        timeBlockMap.put("canEditTBOvt",
                TkServiceLocator.getTKPermissionService().canEditOvertimeEarnCode(timeBlock));

        if (TkServiceLocator.getTKPermissionService().canEditTimeBlockAllFields(principalId, timeBlock)) {
            timeBlockMap.put("canEditTBAll", true);
            timeBlockMap.put("canEditTBAssgOnly", false);
        } else {
            timeBlockMap.put("canEditTBAll", false);
            timeBlockMap.put("canEditTBAssgOnly", true);
        }

        //    tracking any kind of 'mutating' state with this object, it's just a one off modification under a specific circumstance.
        DateTime start = timeBlock.getBeginTimeDisplay();
        DateTime end = timeBlock.getEndTimeDisplay();

        /**
         * This is the timeblock backward pushing logic.
         * the purpose of this is to accommodate the virtual day mode where the start/end period time is not from 12a to 12a.
         * A timeblock will be pushed back if the timeblock is still within the previous interval
         */
        if (timeBlock.getPushBackward()) {
            start = start.minusDays(1);
            end = end.minusDays(1);
        }

        timeBlockMap.put("documentId", timeBlock.getDocumentId());
        timeBlockMap.put("title", workAreaDesc);
        EarnCode ec = HrServiceLocator.getEarnCodeService().getEarnCode(timeBlock.getEarnCode(),
                timeBlock.getBeginDateTime().toLocalDate());
        timeBlockMap.put("earnCode", timeBlock.getEarnCode());
        timeBlockMap.put("earnCodeDesc", ec != null ? ec.getDescription() : StringUtils.EMPTY);
        //TODO: need to cache this or pre-load it when the app boots up
        // EarnCode earnCode = HrServiceLocator.getEarnCodeService().getEarnCode(timeBlock.getEarnCode(), timeBlock.getBeginDateTime().toLocalDate());
        timeBlockMap.put("earnCodeType", timeBlock.getEarnCodeType());

        // TODO: Cleanup the start / end time related properties. We certainly don't need all of them.
        // The ones which are used by the javascript are startDate, endDate, startTime, endTime, startTimeHourMinute, and endTimeHourMinute
        timeBlockMap.put("start", start.toString(ISODateTimeFormat.dateTimeNoMillis()));
        timeBlockMap.put("end", end.toString(ISODateTimeFormat.dateTimeNoMillis()));
        timeBlockMap.put("startDate", start.toString(HrConstants.DT_BASIC_DATE_FORMAT));
        timeBlockMap.put("endDate", end.toString(HrConstants.DT_BASIC_DATE_FORMAT));
        timeBlockMap.put("startNoTz", start.toString(ISODateTimeFormat.dateHourMinuteSecond()));
        timeBlockMap.put("endNoTz", end.toString(ISODateTimeFormat.dateHourMinuteSecond()));
        // start / endTimeHourMinute fields are for only for the display purpose
        timeBlockMap.put("startTimeHourMinute", start.toString(TkConstants.DT_BASIC_TIME_FORMAT));
        timeBlockMap.put("endTimeHourMinute", end.toString(TkConstants.DT_BASIC_TIME_FORMAT));
        // start / endTime are the actual fields used by the adding / editing timeblocks
        timeBlockMap.put("startTime", start.toString(TkConstants.DT_MILITARY_TIME_FORMAT));
        timeBlockMap.put("endTime", end.toString(TkConstants.DT_MILITARY_TIME_FORMAT));
        timeBlockMap.put("id",
                timeBlock.getTkTimeBlockId() == null ? null : timeBlock.getTkTimeBlockId().toString());
        timeBlockMap.put("hours", timeBlock.getHours());
        timeBlockMap.put("amount", timeBlock.getAmount());
        timeBlockMap.put("timezone", timezone);
        timeBlockMap.put("assignment", new AssignmentDescriptionKey(timeBlock.getJobNumber(),
                timeBlock.getWorkArea(), timeBlock.getTask()).toAssignmentKeyString());
        timeBlockMap.put("tkTimeBlockId",
                timeBlock.getTkTimeBlockId() != null ? timeBlock.getTkTimeBlockId() : "");
        timeBlockMap.put("lunchDeleted", timeBlock.isLunchDeleted());

        List<Map<String, Object>> timeHourDetailList = new LinkedList<Map<String, Object>>();
        for (TimeHourDetail timeHourDetail : timeBlock.getTimeHourDetails()) {
            Map<String, Object> timeHourDetailMap = new LinkedHashMap<String, Object>();
            timeHourDetailMap.put("earnCode", timeHourDetail.getEarnCode());
            timeHourDetailMap.put("hours", timeHourDetail.getHours());
            timeHourDetailMap.put("amount", timeHourDetail.getAmount());

            // if there is a lunch hour deduction, add a flag to the timeBlockMap
            if (StringUtils.equals(timeHourDetail.getEarnCode(), "LUN")) {
                timeBlockMap.put("lunchDeduction", true);
            }

            timeHourDetailList.add(timeHourDetailMap);
        }
        timeBlockMap.put("timeHourDetails", JSONValue.toJSONString(timeHourDetailList));

        timeBlockList.add(timeBlockMap);
    }

    //        Map<String, Map<String, Object>> jsonMappedList = new HashMap<String, Map<String, Object>>();
    //        for (Map<String, Object> tbm : timeBlockList) {
    //            String id = (String) tbm.get("id");
    //            jsonMappedList.put(id, tbm);
    //        }
    return JSONValue.toJSONString(timeBlockList);
}

From source file:org.movsim.input.ProjectMetaData.java

License:Open Source License

public String getFormatedTimeWithOffset(double simulationTime) {
    DateTime dateTime = new DateTime(timeOffsetMillis + Math.round(1000 * simulationTime), DateTimeZone.UTC);
    return ISODateTimeFormat.dateTimeNoMillis().print(dateTime);
}

From source file:org.mule.modules.quickbooks.utils.QBDateAdapter.java

License:Open Source License

public QBDateAdapter() {
    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
    DateTimeParser[] parsers = { ISODateTimeFormat.dateTimeNoMillis().getParser(),
            ISODateTimeFormat.dateTime().getParser(),
            DateTimeFormat.forPattern("yyyy-MM-ddZ").withZone(DateTimeZone.getDefault()).getParser() };
    builder.append(ISODateTimeFormat.dateTimeNoMillis().getPrinter(), parsers);
    dateTimeFormatter = builder.toFormatter();
}

From source file:org.mule.modules.zendesk.jersey.DateDeserializer.java

License:CPAL v1.0

public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    return ISODateTimeFormat.dateTimeNoMillis().parseDateTime(json.getAsJsonPrimitive().getAsString()).toDate();
}