Package org.joda.time

Examples of org.joda.time.DateMidnight


  public void shouldBeAbleToConvert() {
    when(request.getAttribute("javax.servlet.jsp.jstl.fmt.locale.request"))
        .thenReturn("pt_br");

    assertThat(converter.convert("05/06/2010", DateMidnight.class, bundle),
        is(equalTo(new DateMidnight(2010, 6, 5))));
  }
View Full Code Here


   * mutually exclusive with method {@link #purgeOlderThan(int)}, hence both should be synchronized (or called from
   * synchronized block like this method). This method must be called outside of a TX as it performs DDL.
   */
  private String maybeAddNewCluster(final ODatabaseDocumentTx db, final long timestamp) {
    final String name = String.format("%s%s", DB_CLUSTER_PREFIX,
        new DateMidnight(timestamp, DateTimeZone.UTC).toString("YYYYMMdd"));
    int cid = db.getClusterIdByName(name); // undocumented: if cluster not exists, returns -1
    if (cid == -1) {
      cid = db.addCluster(name);
      final OSchema schema = db.getMetadata().getSchema();
      final OClass type = schema.getClass(DB_CLASS);
View Full Code Here

  public synchronized void purgeOlderThan(final int days) {
    if (!isStarted()) {
      return;
    }
    try (ODatabaseDocumentTx db = openDb()) {
      final DateMidnight nowDm = new DateMidnight(DateTimeZone.UTC);
      final int prefixLen = DB_CLUSTER_PREFIX.length();
      final int[] cids = db.getMetadata().getSchema().getClass(DB_CLASS).getClusterIds();
      for (int cid : cids) {
        final String name = db.getClusterNameById(cid);
        log.debug("Cluster: {} {}", cid, name);
        if (name.startsWith(DB_CLUSTER_PREFIX)) {
          final int year = Integer.parseInt(name.substring(prefixLen, prefixLen + 4));
          final int month = Integer.parseInt(name.substring(prefixLen + 4, prefixLen + 6));
          final int day = Integer.parseInt(name.substring(prefixLen + 6, prefixLen + 8));
          final DateMidnight clusterDm = new DateMidnight(year, month, day, DateTimeZone.UTC);
          if (Days.daysBetween(clusterDm, nowDm).getDays() >= days) {
            log.info("Cluster {}, is {} days old, purging it", name, Days.daysBetween(clusterDm, nowDm).getDays());
            OSchema schema = db.getMetadata().getSchema();
            OClass type = schema.getClass(DB_CLASS);
            type.removeClusterId(cid);
View Full Code Here

    assertThat(res.get(1).getData(), hasEntry("place", "2nd"));
  }

  @Test
  public void partitioningByDay() throws Exception {
    final long now = new DateMidnight(DateTimeZone.UTC).getMillis();
    underTest.add(new EntryRecord(now - TimeUnit.DAYS.toMillis(2), "TEST", "1", ImmutableMap.of("day", "1")));
    underTest.add(new EntryRecord(now - TimeUnit.DAYS.toMillis(2), "TEST", "2", ImmutableMap.of("day", "1")));
    underTest.add(new EntryRecord(now - TimeUnit.DAYS.toMillis(1), "TEST", "1", ImmutableMap.of("day", "2")));
    underTest.add(new EntryRecord(now - TimeUnit.DAYS.toMillis(1), "TEST", "2", ImmutableMap.of("day", "2")));
    underTest.add(new EntryRecord(now, "TEST", "1", ImmutableMap.of("day", "3")));
View Full Code Here

    Calendar calendar = new Calendar();

    // build months
    List<DateTime> months = calendar.getMonths();

    DateMidnight thisMonth = getDefaultDateTime().toDateMidnight().withDayOfMonth(1);
    months.add(thisMonth.toDateTime());

    // display last 6 months
    while (months.size() < 6) {
      thisMonth = thisMonth.minusMonths(1);
      months.add(thisMonth.toDateTime());
    }

    reverse(months);

    // build selectedMonth
    if (year != null) {
      notNull(month, "month is required if year is specified");
      DateTime selectedMonth = new DateMidnight().withDayOfMonth(1).withYear(year).withMonthOfYear(month).toDateTime();
      calendar.setSelectedMonth(selectedMonth);
    }

    return calendar;
  }
View Full Code Here

        executeDataSet(XML_DATASET_PATH + new TestUtil().getTestDatasetFilename(XML_REGRESSION_TEST_DATASET));
    }

    @Test
    public void testMarkPatientDead() throws Exception {
        final Date date = new DateMidnight().toDate();
        new RegressionTestHelper() {

            @Override
            public String getFormName() {
                return "markPatientDead";
View Full Code Here

                jp.nextToken(); // VALUE_NUMBER_INT
                int day = jp.getIntValue();
                if (jp.nextToken() != JsonToken.END_ARRAY) {
                    throw ctxt.wrongTokenException(jp, JsonToken.END_ARRAY, "after DateMidnight ints");
                }
                return new DateMidnight(year, month, day);
            }
            switch (jp.getCurrentToken()) {
            case VALUE_NUMBER_INT:
                return new DateMidnight(jp.getLongValue());           
            case VALUE_STRING:
                DateTime local = parseLocal(jp);
                if (local == null) {
                    return null;
                }
View Full Code Here

                        td = timeDimensionDao.createTimeDimension(localTime);
                        times.put(localTime, td);
                    }
                   
                    //get/create DateDimension
                    final DateMidnight dateMidnight = nextDateTime.toDateMidnight();
                    DateDimension dd = dates.get(dateMidnight);
                    if (dd == null) {
                        dd = dateDimensionDao.createDateDimension(dateMidnight, 0, null);
                        dates.put(dateMidnight, dd);
                    }
View Full Code Here

       
       
        this.executeInTransaction(new CallableWithoutResult() {
            @Override
            protected void callWithoutResult() {
                DateMidnight date = new DateMidnight(2012, 1, 1);
               
                for (int i = 0; i < 7; i++) {
                    dateDimensionDao.createDateDimension(date, 0, null);
                    date = date.plusDays(1);
                }
            }
        });
       
        this.execute(new CallableWithoutResult() {
            @Override
            protected void callWithoutResult() {
                DateMidnight date = new DateMidnight(2012, 1, 1);
                final DateDimension dateDimension = dateDimensionDao.getDateDimensionByDate(date);
                assertNotNull(dateDimension);
            }
        });
       
       
        this.execute(new CallableWithoutResult() {
            @Override
            protected void callWithoutResult() {
                final List<DateDimension> dateDimensions = dateDimensionDao.getDateDimensions();
               
                assertEquals(7, dateDimensions.size());
            }
        });
       
       
        this.execute(new CallableWithoutResult() {
            @Override
            protected void callWithoutResult() {
                final DateMidnight start = new DateMidnight(2012, 1, 2);
                final DateMidnight end = new DateMidnight(2012, 1, 6);
                final List<DateDimension> dateDimensions = dateDimensionDao.getDateDimensionsBetween(start, end);
               
                assertEquals(4, dateDimensions.size());
            }
        });
View Full Code Here

                final List<AcademicTermDetail> academicTermDetail = eventAggregationManagementDao.getAcademicTermDetails();
                assertEquals(0, academicTermDetail.size());
               
                List<AcademicTermDetail> academicTermDetails = new ArrayList<AcademicTermDetail>();
               
                academicTermDetails.add(new AcademicTermDetailImpl(new DateMidnight(2012, 1, 1), new DateMidnight(2012, 6, 1), "Spring 2012"));
                academicTermDetails.add(new AcademicTermDetailImpl(new DateMidnight(2012, 6, 1), new DateMidnight(2012, 9, 1), "Summer 2012"));
                academicTermDetails.add(new AcademicTermDetailImpl(new DateMidnight(2012, 9, 1), new DateMidnight(2013, 1, 1), "Fall 2012"));
               
               
                eventAggregationManagementDao.setAcademicTermDetails(academicTermDetails);
            }
        });

        try {
            this.executeInTransaction(new CallableWithoutResult() {
                @Override
                protected void callWithoutResult() {
                    final List<AcademicTermDetail> academicTermDetail = eventAggregationManagementDao.getAcademicTermDetails();
                    assertEquals(3, academicTermDetail.size());
                   
                    academicTermDetail.add(new AcademicTermDetailImpl(new DateMidnight(2012, 1, 1), new DateMidnight(2013, 6, 1), "Spring 2013"));
                   
                    try {
                        eventAggregationManagementDao.setAcademicTermDetails(academicTermDetail);
                        fail();
                    }
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.