Package org.joda.time

Examples of org.joda.time.MutableDateTime


    }

    public void testWeekdayNames() {
        DateTimeFormatter printer = DateTimeFormat.forPattern("EEEE");
        for (int i=0; i<ZONES.length; i++) {
            MutableDateTime mdt = new MutableDateTime(2004, 1, 1, 1, 20, 30, 40, ZONES[i]);
            for (int day=1; day<=366; day++) {
                mdt.setDayOfYear(day);
                int weekday = mdt.getDayOfWeek();
                String weekdayText = printer.print(mdt);
                assertEquals(WEEKDAYS[weekday], weekdayText);
            }
        }
    }
View Full Code Here


    public void testHalfdayNames() {
        DateTimeFormatter printer = DateTimeFormat.forPattern("a");
        for (int i=0; i<ZONES.length; i++) {
            Chronology chrono = ISOChronology.getInstance(ZONES[i]);
            MutableDateTime mdt = new MutableDateTime(2004, 5, 30, 0, 20, 30, 40, chrono);
            for (int hour=0; hour<24; hour++) {
                mdt.setHourOfDay(hour);
                int halfday = mdt.get(chrono.halfdayOfDay());
                String halfdayText = printer.print(mdt);
                assertEquals(HALFDAYS[halfday], halfdayText);
            }
        }
    }
View Full Code Here

        assertEquals(expect, g.withChronology(BUDDHIST_PARIS).parseDateTime("2004-06-09T10:20:30Z"));
    }

    //-----------------------------------------------------------------------
    public void testParseMutableDateTime_simple() {
        MutableDateTime expect = null;
        expect = new MutableDateTime(2004, 6, 9, 11, 20, 30, 0, LONDON);
        assertEquals(expect, g.parseMutableDateTime("2004-06-09T10:20:30Z"));
       
        try {
            g.parseMutableDateTime("ABC");
            fail();
View Full Code Here

            fail();
        } catch (IllegalArgumentException ex) {}
    }

    public void testParseMutableDateTime_zone() {
        MutableDateTime expect = null;
        expect = new MutableDateTime(2004, 6, 9, 11, 20, 30, 0, LONDON);
        assertEquals(expect, g.withZone(LONDON).parseMutableDateTime("2004-06-09T10:20:30Z"));
       
        expect = new MutableDateTime(2004, 6, 9, 11, 20, 30, 0, LONDON);
        assertEquals(expect, g.withZone(null).parseMutableDateTime("2004-06-09T10:20:30Z"));
       
        expect = new MutableDateTime(2004, 6, 9, 12, 20, 30, 0, PARIS);
        assertEquals(expect, g.withZone(PARIS).parseMutableDateTime("2004-06-09T10:20:30Z"));
    }
View Full Code Here

            from = new DateTime(Long.parseLong(firstTimestamp) * 1000, DateTimeZone.UTC);
        } else {
            from = DateTime.parse(histogram.getHistogramBoundaries().getFrom());
        }
        final DateTime to = DateTime.parse(histogram.getHistogramBoundaries().getTo());
        final MutableDateTime currentTime = new MutableDateTime(from);

        final Duration step = estimateIntervalStep(histogram.getInterval());
        final int dataPoints = (int) ((to.getMillis() - from.getMillis()) / step.getMillis());

        // using the absolute value guarantees, that there will always be enough values for the given resolution
        final int factor = (maxDataPoints != -1 && dataPoints > maxDataPoints) ? dataPoints / maxDataPoints : 1;

        int index = 0;
        floorToBeginningOfInterval(histogram.getInterval(), currentTime);
        while (currentTime.isBefore(to) || currentTime.isEqual(to)) {
            if (index % factor == 0) {
                String timestamp = Long.toString(currentTime.getMillis() / 1000);
                Long result = histogramResults.get(timestamp);
                Map<String, Long> point = Maps.newHashMap();
                point.put("x", Long.parseLong(timestamp));
                point.put("y", result != null ? result : 0);
                points.add(point);
View Full Code Here

        assertEquals(ISO, ReadableInstantConverter.INSTANCE.getChronology(new Instant(123L), (DateTimeZone) null));
        assertEquals(ISO, ReadableInstantConverter.INSTANCE.getChronology(new DateTime(123L), (DateTimeZone) null));
       
        assertEquals(ISO_PARIS, ReadableInstantConverter.INSTANCE.getChronology(new DateTime(123L, new MockBadChronology()), PARIS));
       
        MutableDateTime mdt = new MutableDateTime() {
            public Chronology getChronology() {
                return null; // bad
            }
        };
        assertEquals(ISO_PARIS, ReadableInstantConverter.INSTANCE.getChronology(mdt, PARIS));
View Full Code Here

    public void testGetChronology_Object_nullChronology() throws Exception {
        assertEquals(ISO.withUTC(), ReadableInstantConverter.INSTANCE.getChronology(new Instant(123L), (Chronology) null));
        assertEquals(ISO, ReadableInstantConverter.INSTANCE.getChronology(new DateTime(123L), (Chronology) null));
       
        MutableDateTime mdt = new MutableDateTime() {
            public Chronology getChronology() {
                return null; // bad
            }
        };
        assertEquals(ISO, ReadableInstantConverter.INSTANCE.getChronology(mdt, (Chronology) null));
View Full Code Here

    LocalDate end = new LocalDate();
    LocalDate start = end.minusYears(1);

    List<File> result = new ArrayList<File>();
    IPath[] storagePaths = XmlPlugin.getDefault().getStoragePaths();
    MutableDateTime date = start.toDateTime(new LocalTime(0, 0, 0)).toMutableDateTime();
    while (new LocalDate(date.toInstant().getMillis()).compareTo(end) <= 0) {

      for (IPath path : storagePaths) {
        File f = store.getDataFile(new LocalDate(date.getMillis()), path);
        if (f.exists()) {
          result.add(f);
        }
      }
      date.addMonths(1);
    }
    assertEquals(result.size(), store.getDataFiles(start, end).size());
  }
View Full Code Here

      int day = cal.get(Calendar.DAY_OF_MONTH);
      int hours = (hoursInput == null ? 0 : hoursInput % 24);
      int minutes = (minutesInput == null ? 0 : minutesInput);

      // Use the input to create a date object with proper timezone
      MutableDateTime date = new MutableDateTime(year, month, day, hours, minutes, 0, 0,
        DateTimeZone.forTimeZone(getClientTimeZone()));

      // Adjust for halfday if needed
      if (use12HourFormat())
      {
        int halfday = (amOrPmInput == AM_PM.PM ? 1 : 0);
        date.set(DateTimeFieldType.halfdayOfDay(), halfday);
        date.set(DateTimeFieldType.hourOfHalfday(), hours % 12);
      }

      // The date will be in the server's timezone
      setConvertedInput(new Date(date.getMillis()));
    }
    catch (RuntimeException e)
    {
      DateTimeField.this.error(e.getMessage());
      invalid();
View Full Code Here

      if (zone != null)
      {
        modelObject = changeTimeZone(modelObject, zone);
      }

      MutableDateTime mDate = new MutableDateTime(modelObject);

      date = mDate.toDate();

      if (use12HourFormat)
      {
        int hourOfHalfDay = mDate.get(DateTimeFieldType.hourOfHalfday());
        hours = hourOfHalfDay == 0 ? 12 : hourOfHalfDay;
      }
      else
      {
        hours = mDate.get(DateTimeFieldType.hourOfDay());
      }

      amOrPm = (mDate.get(DateTimeFieldType.halfdayOfDay()) == 0) ? AM_PM.AM : AM_PM.PM;
      minutes = mDate.getMinuteOfHour();
    }

    super.onBeforeRender();
  }
View Full Code Here

TOP

Related Classes of org.joda.time.MutableDateTime

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.