Examples of DateTimeFormatter


Examples of org.joda.time.format.DateTimeFormatter

        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

Examples of org.joda.time.format.DateTimeFormatter

  @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

Examples of org.joda.time.format.DateTimeFormatter

     * @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

Examples of org.joda.time.format.DateTimeFormatter

    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

Examples of org.joda.time.format.DateTimeFormatter

           
            // 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

Examples of org.joda.time.format.DateTimeFormatter

    if (Strings.isEmpty(value))
    {
      return null;
    }

    DateTimeFormatter format = getFormat(locale);
    if (format == null)
    {
      throw new IllegalStateException("format must be not null");
    }

    if (applyTimeZoneDifference)
    {
      TimeZone zone = getClientTimeZone();
      DateTime dateTime = null;

      // set time zone for client
      format = format.withZone(getTimeZone());

      try
      {
        // parse date retaining the time of the submission
        dateTime = format.parseDateTime(value);
      }
      catch (RuntimeException e)
      {
        throw new ConversionException(e);
      }
      // apply the server time zone to the parsed value
      if (zone != null)
      {
        dateTime = dateTime.withZoneRetainFields(DateTimeZone.forTimeZone(zone));
      }

      return dateTime.toDate();
    }
    else
    {
      try
      {
        DateTime date = format.parseDateTime(value);
        return date.toDate();
      }
      catch (RuntimeException e)
      {
        throw new ConversionException(e);
View Full Code Here

Examples of org.joda.time.format.DateTimeFormatter

   *      java.util.Locale)
   */
  public String convertToString(Date value, Locale locale)
  {
    DateTime dt = new DateTime((value).getTime(), getTimeZone());
    DateTimeFormatter format = getFormat(locale);

    if (applyTimeZoneDifference)
    {
      TimeZone zone = getClientTimeZone();
      if (zone != null)
      {
        // apply time zone to formatter
        format = format.withZone(DateTimeZone.forTimeZone(zone));
      }
    }
    return format.print(dt);
  }
View Full Code Here

Examples of org.joda.time.format.DateTimeFormatter

        String date = input.get(0).toString();
        String format = input.get(1).toString();

        // See http://joda-time.sourceforge.net/api-release/org/joda/time/format/DateTimeFormat.html
        DateTimeFormatter parser = DateTimeFormat.forPattern(format);
        DateTime result = parser.parseDateTime(date);

        return result.toString();
    }
View Full Code Here

Examples of org.joda.time.format.DateTimeFormatter

      "2003-10-11T22:14:15.003Z", "2003-08-24T05:14:15.000003-07:00",
      "2012-04-13T11:11:11-08:00", "2012-04-13T08:08:08.0001+00:00"
    };

    SyslogParser parser = new SyslogParser();
    DateTimeFormatter jodaParser = ISODateTimeFormat.dateTimeParser();

    for (String ex : examples) {
      Assert.assertEquals(
          "Problem parsing date string: " + ex,
          jodaParser.parseMillis(ex),
          parser.parseRfc5424Date(ex));
    }
  }
View Full Code Here

Examples of org.joda.time.format.DateTimeFormatter

    if (Strings.isEmpty(value))
    {
      return null;
    }

    DateTimeFormatter format = getFormat(locale);
    if (format == null)
    {
      throw new IllegalStateException("format must be not null");
    }

    if (applyTimeZoneDifference)
    {
      TimeZone zone = getClientTimeZone();
      DateTime dateTime = null;
     
      // set time zone for client
      format = format.withZone(getTimeZone());       

      try
      {
        // parse date retaining the time of the submission
        dateTime = format.parseDateTime(value);       
      }
      catch (RuntimeException e)
      {
        throw new ConversionException(e);
      }
      // apply the server time zone to the parsed value
      if (zone != null)
      {
        dateTime = dateTime.withZoneRetainFields(DateTimeZone.forTimeZone(zone));
      }     
     
      return dateTime.toDate();
    }
    else
    {
      try
      {
        DateTime date = format.parseDateTime(value);
        return date.toDate();
      }
      catch (RuntimeException e)
      {
        throw new ConversionException(e);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.