Package org.joda.time.format

Examples of org.joda.time.format.DateTimeFormatter


        assertEquals(DateTimeZone.getDefault(), constructed.getZone());
        assertEquals(DateTimeZone.forOffsetHours(1), parsed.getZone());
    }

    public void testParse_formatter() throws Throwable {
        DateTimeFormatter f = DateTimeFormat.forPattern("yyyy--dd MM HH").withChronology(ISOChronology.getInstance(PARIS));
        assertEquals(new DateTime(2010, 6, 30, 13, 0, ISOChronology.getInstance(PARIS)), DateTime.parse("2010--30 06 13", f));
    }
View Full Code Here


        assertEquals(new MonthDay(6, 30), MonthDay.parse("2010-06-30"));
        assertEquals(new MonthDay(1, 2), MonthDay.parse("2010-002"));
    }

    public void testParse_formatter() throws Throwable {
        DateTimeFormatter f = DateTimeFormat.forPattern("yyyy--dd MM").withChronology(ISOChronology.getInstance(PARIS));
        assertEquals(new MonthDay(6, 30), MonthDay.parse("2010--30 06", f));
    }
View Full Code Here

        assertEquals(new YearMonth(2010, 6), YearMonth.parse("2010-06-30"));
        assertEquals(new YearMonth(2010, 1), YearMonth.parse("2010-002"));
    }

    public void testParse_formatter() throws Throwable {
        DateTimeFormatter f = DateTimeFormat.forPattern("yyyy--MM").withChronology(ISOChronology.getInstance(PARIS));
        assertEquals(new YearMonth(2010, 6), YearMonth.parse("2010--06", f));
    }
View Full Code Here

        assertEquals(new LocalDate(2010, 6, 30), LocalDate.parse("2010-06-30"));
        assertEquals(new LocalDate(2010, 1, 2), LocalDate.parse("2010-002"));
    }

    public void testParse_formatter() throws Throwable {
        DateTimeFormatter f = DateTimeFormat.forPattern("yyyy--dd MM").withChronology(ISOChronology.getInstance(PARIS));
        assertEquals(new LocalDate(2010, 6, 30), LocalDate.parse("2010--30 06", f));
    }
View Full Code Here

        assertEquals(new MutableDateTime(2010, 6, 30, 1, 20, 0, 0, ISOChronology.getInstance(DateTimeZone.forOffsetHours(2))), MutableDateTime.parse("2010-06-30T01:20+02:00"));
        assertEquals(new MutableDateTime(2010, 1, 2, 14, 50, 0, 0, ISOChronology.getInstance(LONDON)), MutableDateTime.parse("2010-002T14:50"));
    }

    public void testParse_formatter() throws Throwable {
        DateTimeFormatter f = DateTimeFormat.forPattern("yyyy--dd MM HH").withChronology(ISOChronology.getInstance(PARIS));
        assertEquals(new MutableDateTime(2010, 6, 30, 13, 0, 0, 0, ISOChronology.getInstance(PARIS)), MutableDateTime.parse("2010--30 06 13", f));
    }
View Full Code Here

        Object field = msg.getSource().get("timestamp");
        if (field == null) {
            throw new RuntimeException("Document has no field timestamp.");
        }

        DateTimeFormatter formatter = DateTimeFormat.forPattern(ES_DATE_FORMAT).withZoneUTC();
        DateTime dt = formatter.parseDateTime(field.toString());

        return (int) (dt.getMillis()/1000);
    }
View Full Code Here

  @Override
  protected void respond(AjaxRequestTarget target) {
    Request r = target.getPage().getRequest();
    ViewType type = ViewType.forCode(r.getRequestParameters().getParameterValue("view").toString());
    DateTimeFormatter fmt = ISODateTimeFormat.dateTimeParser().withZone(DateTimeZone.UTC);
    DateMidnight start = fmt.parseDateTime(r.getRequestParameters().getParameterValue("start").toString())
      .toDateMidnight();
    DateMidnight end = fmt.parseDateTime(r.getRequestParameters().getParameterValue("end").toString())
      .toDateMidnight();
    DateMidnight visibleStart = fmt.parseDateTime(
      r.getRequestParameters().getParameterValue("visibleStart").toString()).toDateMidnight();
    DateMidnight visibleEnd = fmt
      .parseDateTime(r.getRequestParameters().getParameterValue("visibleEnd").toString()).toDateMidnight();
    View view = new View(type, start, end, visibleStart, visibleEnd);
    CalendarResponse response = new CalendarResponse(getCalendar(), target);
    onViewDisplayed(view, response);
  }
View Full Code Here

     * @param day
     *            an ISO8601 formatted String (non millis)
     * @return a DateTime instance at midnight in "Market time"
     */
    public static DateTime isoDayToDateTime(final String day) {
        final DateTimeFormatter fmt = isoFormat.withZone(marketTimeZone);
        final DateTime parsed = fmt.parseDateTime(day);
        // set to start of day
        final DateTime result = parsed.withMillisOfDay(0);
        return result;
    }
View Full Code Here

    private int importCsv(FileItem item) throws IOException, TranslatableException {
        CSVReader csvReader = new CSVReader(new InputStreamReader(item.getInputStream()));
        DataPointDao dataPointDao = new DataPointDao();
        PointValueDao pointValueDao = Common.databaseProxy.newPointValueDao();
        DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy/MM/dd HH:mm:ss");

        // Basic validation
        String[] nextLine = csvReader.readNext();
        if (nextLine == null)
            throw new TranslatableException(new TranslatableMessage("dataImport.import.noData"));
        if (nextLine.length < 2)
            throw new TranslatableException(new TranslatableMessage("dataImport.import.noPoints"));

        // Find the points by XID
        DataPointVO[] vos = new DataPointVO[nextLine.length - 1];

        for (int i = 1; i < nextLine.length; i++) {
            if (StringUtils.isBlank(nextLine[i]))
                throw new TranslatableException(new TranslatableMessage("dataImport.import.badXid", i));

            DataPointVO vo = dataPointDao.getDataPoint(nextLine[i]);
            if (vo == null)
                throw new TranslatableException(new TranslatableMessage("dataImport.import.xidNotFound", nextLine[i]));

            vos[i - 1] = vo;
        }

        // Find the RTs for the points if they are enabled
        DataPointRT[] rts = new DataPointRT[vos.length];
        for (int i = 0; i < vos.length; i++)
            rts[i] = Common.runtimeManager.getDataPoint(vos[i].getId());

        // Import the data
        int count = 0;
        while ((nextLine = csvReader.readNext()) != null) {
            // The first value is always a date.
            long time = dtf.parseDateTime(nextLine[0]).getMillis();

            // The rest of the values are point samples.
            for (int i = 1; i < nextLine.length; i++) {
                DataValue value = DataValue.stringToValue(nextLine[i], vos[i - 1].getPointLocator().getDataTypeId());
                PointValueTime pvt = new PointValueTime(value, time);
View Full Code Here

           
            // Convert String to Calendar or sql.Date/Time/Timestamp
            // First convert it to a milliseconds. We think it's GMT because no TZ is specified in the String.
            long date;
            try {
                DateTimeFormatter dateFmt = getFormat().withZone(DateTimeZone.UTC);
                date = dateFmt.parseMillis(value);
            }
            catch (IllegalArgumentException e) {
                throw new ConversionException("Cannot convert '" + value + "' to a Date.")
                    .setSourceValue(value)
                    .setTargetType(type)
View Full Code Here

TOP

Related Classes of org.joda.time.format.DateTimeFormatter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.