Package org.joda.time

Examples of org.joda.time.DateMidnight


  }
 
  @Test
  public void canConvertDate_toGregorianCalendar() {
    LocalDate lt = new LocalDate(2000, 1, 2);
    DateMidnight dm = lt.toDateMidnight(DateTimeZone.UTC);
   
    XMLGregorianCalendar gc = XmlUtils.asXMLGregorianCalendar(dm.toDate());
    Assert.assertEquals("2000-01-02T00:00:00.000Z", gc.toXMLFormat());
  }
View Full Code Here


  }
 
  @Test
  public void canConvert_GregorianCalendar_toDate() {
    LocalDate lt = new LocalDate(2000, 1, 2);
    DateMidnight dm = lt.toDateMidnight(DateTimeZone.UTC);
   
    Date d = dm.toDate();
   
    XMLGregorianCalendar gc = XmlUtils.asXMLGregorianCalendar(d);
    Date dConv = XmlUtils.asDate(gc);
   
    Assert.assertEquals(d, dConv);
View Full Code Here

  @Test
  public void testParseProjectInJira4x4() throws JSONException, URISyntaxException {
    final Project project = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/project/project-jira-4-4.json"));
    assertEquals("TST", project.getKey()); //2010-08-25
    assertEquals(new DateMidnight(2010, 8, 25).toInstant(), Iterables.getLast(project.getVersions()).getReleaseDate().toInstant());
        assertEquals("Test Project", project.getName());
    final OptionalIterable<IssueType> issueTypes = project.getIssueTypes();
    assertTrue(issueTypes.isSupported());
    assertThat(issueTypes, containsInAnyOrder(
        new IssueType(TestUtil.toUri("http://localhost:2990/jira/rest/api/latest/issueType/1"), null, "Bug", false, null, null),
View Full Code Here

  @Test
  public void testParseProjectInJira5x0() throws JSONException, URISyntaxException {
    final Project project = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/project/project-jira-5-0.json"));
    assertEquals("TST", project.getKey());
    assertEquals(new DateMidnight(2010, 8, 25).toInstant(), Iterables.getLast(project.getVersions()).getReleaseDate().toInstant());
    assertEquals("Test Project", project.getName());
    final OptionalIterable<IssueType> issueTypes = project.getIssueTypes();
    assertTrue(issueTypes.isSupported());
    assertThat(issueTypes, containsInAnyOrder(
        new IssueType(TestUtil.toUri("http://localhost:2990/jira/rest/api/latest/issuetype/1"), 1L, "Bug", false, "A problem which impairs or prevents the functions of the product.", TestUtil.toUri("http://localhost:2990/jira/images/icons/bug.gif")),
View Full Code Here

        assertEquals(true, GregorianChronology.getInstance().millisOfSecond().isSupported());
    }

    public void testMaximumValue() {
        YearMonthDay ymd1 = new YearMonthDay(1999, DateTimeConstants.FEBRUARY, 1);
        DateMidnight dm1 = new DateMidnight(1999, DateTimeConstants.FEBRUARY, 1);
        Chronology chrono = GregorianChronology.getInstance();
        assertEquals(28, chrono.dayOfMonth().getMaximumValue(ymd1));
        assertEquals(28, chrono.dayOfMonth().getMaximumValue(dm1.getMillis()));
    }
View Full Code Here

        assertEquals(end, start.plusMinutes(22 * 60));
        assertEquals(start, end.minusMinutes(22 * 60));
    }

    public void testMaximumValue() {
        DateMidnight dt = new DateMidnight(1570, 1, 1, GJChronology.getInstance());
        while (dt.getYear() < 1590) {
            dt = dt.plusDays(1);
            YearMonthDay ymd = dt.toYearMonthDay();
            assertEquals(dt.year().getMaximumValue(), ymd.year().getMaximumValue());
            assertEquals(dt.monthOfYear().getMaximumValue(), ymd.monthOfYear().getMaximumValue());
            assertEquals(dt.dayOfMonth().getMaximumValue(), ymd.dayOfMonth().getMaximumValue());
        }
    }
View Full Code Here

        assertEquals(end, start.withFieldAdded(DurationFieldType.days(), 365 + 365 + 365 + 366));
        assertEquals(start, end.withFieldAdded(DurationFieldType.days(), -(365 + 365 + 365 + 366)));
    }

    public void testMaximumValue() {
        DateMidnight dt = new DateMidnight(1570, 1, 1);
        while (dt.getYear() < 1590) {
            dt = dt.plusDays(1);
            YearMonthDay ymd = dt.toYearMonthDay();
            assertEquals(dt.year().getMaximumValue(), ymd.year().getMaximumValue());
            assertEquals(dt.monthOfYear().getMaximumValue(), ymd.monthOfYear().getMaximumValue());
            assertEquals(dt.dayOfMonth().getMaximumValue(), ymd.dayOfMonth().getMaximumValue());
        }
    }
View Full Code Here

    if (applyTimeZoneDifference)
    {
      TimeZone zone = getClientTimeZone();
      // instantiate now/ current time
      MutableDateTime dt = new MutableDateTime(new DateMidnight());
      if (zone != null)
      {
        // set time zone for client
        format = format.withZone(DateTimeZone.forTimeZone(zone));
        dt.setZone(DateTimeZone.forTimeZone(zone));
View Full Code Here

    if (applyTimeZoneDifference)
    {
      TimeZone zone = getClientTimeZone();
      // instantiate now/ current time
      MutableDateTime dt = new MutableDateTime(new DateMidnight());
      if (zone != null)
      {
        // set time zone for client
        format = format.withZone(DateTimeZone.forTimeZone(zone));
        dt.setZone(DateTimeZone.forTimeZone(zone));
View Full Code Here

   * @param slaWorkingHours
   * @return
   */
  public Duration calculateElapsedTime(DateTime lastCalculated, DateTime now,
      int slaWorkingHours) {
    DateMidnight dateBeingProcessed = new DateMidnight(lastCalculated);
    Interval processingInterval = getEntireDayIntervalForDate(dateBeingProcessed);
    Duration duration = new Duration(null);
    while (processingInterval.contains(now)
        || processingInterval.isBefore(now)) {
      Interval workingHours = getWorkingIntervalForDate(
          dateBeingProcessed, slaWorkingHours);

      // process the day
      // if the last calculated date is within the current 24hours being
      // processed.
      if (processingInterval.contains(lastCalculated)) {
        // set start to last calc'd or start or working period if after
        // last calced
        if (workingHours.getStart().isAfter(lastCalculated)) {
          // leave start of working hours as is
        } else if (workingHours.contains(lastCalculated)) {
          workingHours = workingHours.withStart(lastCalculated);
        } else if (workingHours.getEnd().isBefore(lastCalculated)) {
          workingHours = new Interval(lastCalculated, lastCalculated); // zero
          // time
          // duration
        }
      }
      if (processingInterval.contains(now)) {
        // set end to now if now in working period
        if (workingHours.getStart().isAfter(now)) {
          workingHours = new Interval(now, now); // zero time duration
        } else if (workingHours.contains(now)) {
          workingHours = workingHours.withEnd(now);
        } else if (workingHours.getEnd().isBefore(now)) {
          // leave end of working hours as is
        }
      }
      duration = duration.plus(workingHours.toDuration());
      dateBeingProcessed = dateBeingProcessed.plusDays(1);
      processingInterval = getEntireDayIntervalForDate(dateBeingProcessed);
    }
    System.out.println(duration.toPeriod());
    return duration;
  }
View Full Code Here

TOP

Related Classes of org.joda.time.DateMidnight

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.