Example usage for java.util Date equals

List of usage examples for java.util Date equals

Introduction

In this page you can find the example usage for java.util Date equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Compares two dates for equality.

Usage

From source file:org.jumpmind.symmetric.statistic.AbstractStatsByPeriodMap.java

public AbstractStatsByPeriodMap(Date start, Date end, List<M> list, int periodSizeInMinutes) {
    Iterator<M> stats = list.iterator();
    Calendar startCal = Calendar.getInstance();
    startCal.setTime(start);//from   w ww .  ja v  a 2  s .c o m
    startCal.set(Calendar.SECOND, 0);
    startCal.set(Calendar.MILLISECOND, 0);
    startCal.set(Calendar.MINUTE, round(startCal.get(Calendar.MINUTE)));
    Date periodStart = startCal.getTime();
    Date periodEnd = DateUtils.addMinutes(periodStart, periodSizeInMinutes);
    M stat = null;
    while (periodStart.before(end)) {
        if (stat == null && stats.hasNext()) {
            stat = stats.next();
        }
        if (stat != null && (periodStart.equals(stat.getStartTime()) || periodStart.before(stat.getStartTime()))
                && periodEnd.after(stat.getStartTime())) {
            add(periodStart, stat);
            stat = null;
        } else {
            if (stat != null && stat.getStartTime().before(periodStart)) {
                stat = null;
            }
            if (!containsKey(periodStart)) {
                addBlank(periodStart);
            }
            periodStart = periodEnd;
            periodEnd = DateUtils.addMinutes(periodStart, periodSizeInMinutes);
        }
    }
}

From source file:de.alpharogroup.lang.ObjectExtensionsTest.java

/**
 * Test generic clone method./*from   ww  w  .  j  ava2  s. co m*/
 */
@Test(enabled = false)
public void testClone() {
    final Date past = CreateDateUtils.newDate(2009, 3, 26, 10, 37, 04);
    final Date otherCopy = ObjectExtensions.clone(past);

    boolean result = past.equals(otherCopy);
    AssertJUnit.assertTrue("Cloned object should be equal with the source object.", result);

    final String aString = "Hy there...";

    final String clonedString = ObjectExtensions.clone(aString);

    result = aString.equals(clonedString);
    AssertJUnit.assertTrue("Cloned object should be equal with the source object.", result);

    final A a = new A();
    a.setA("a");

    final A anotherCopy = ObjectExtensions.clone(a);

    result = a.equals(anotherCopy);
    AssertJUnit.assertTrue("Cloned object should be equal with the source object.", result);
}

From source file:org.vosao.search.impl.SearchIndexImpl.java

private void refreshIndex() {
    Date date = (Date) getBusiness().getSystemService().getCache().getMemcache().get(getIndexKey());
    if (index == null || date == null || !date.equals(indexModDate)) {
        loadIndex();//  www  .ja va 2 s  .c  o m
    }
}

From source file:net.spfbl.whois.Handle.java

/**
 * Altera a data de criao do registro.//from   w w  w  . jav  a 2s.c  o  m
 * @param created a nova data de criao do registro.
 * @throws ProcessException se houver falha no processamento.
 */
public void setCreated(String created) throws ProcessException {
    if (created == null) {
        throw new ProcessException("ERROR: INVALID CREATED");
    } else if (created.length() < 8) {
        this.created = null;
    } else {
        try {
            Date createdDate = DATE_FORMATTER.parse(created);
            if (!createdDate.equals(this.created)) {
                this.created = createdDate;
                // Atualiza flag de atualizao.
                CHANGED = true;
            }
        } catch (ParseException ex) {
            this.created = null;
            Server.logError(ex);
        }
    }
}

From source file:com.inkubator.hrm.service.impl.JadwalKerjaMassExceptionMessagesListener.java

@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, timeout = 50, rollbackFor = Exception.class)
public void onMessage(Message message) {
    try {//from ww  w  .ja va 2  s.  c o m
        TextMessage textMessage = (TextMessage) message;
        JSONObject jSONObject = new JSONObject(textMessage.getText());
        long workingGroupId = Long.parseLong(jSONObject.getString("groupWorkingId"));
        String listEmp = jSONObject.getString("listEmpId");
        Date createOn = new SimpleDateFormat("dd-MM-yyyy hh:mm").parse(jSONObject.getString("createDate"));
        String createBy = jSONObject.getString("createBy");
        String startDateString = jSONObject.getString("startDate");
        String endDateString = jSONObject.getString("endDate");
        Date startProposeDate = new SimpleDateFormat("dd-MM-yyyy hh:mm")
                .parse(jSONObject.getString("startDate"));
        Gson gson = new GsonBuilder().create();
        //            List<TempJadwalKaryawan> dataToDelete = new ArrayList<>();
        TypeToken<List<Long>> token = new TypeToken<List<Long>>() {
        };
        List<Long> dataEmpId = gson.fromJson(listEmp, token.getType());
        //Date now = new Date();
        WtGroupWorking groupWorking = wtGroupWorkingDao.getEntiyByPK(workingGroupId);
        Date startDate = groupWorking.getBeginTime();//tidak ditempatkan di dalam loop karena untuk groupworking yang sama
        Date endDate = groupWorking.getEndTime();

        int numberOfDay = DateTimeUtil.getTotalDayDifference(startDate, endDate);
        int totalDateDif = DateTimeUtil.getTotalDayDifference(startDate, startProposeDate) + 1;
        int num = numberOfDay + 1;
        int hasilBagi = (totalDateDif) / (num);

        Date tanggalAkhirJadwal = new SimpleDateFormat("dd-MM-yyyy hh:mm")
                .parse(jSONObject.getString("endDate"));
        //        String dayBegin = new SimpleDateFormat("EEEE").format(endDate);
        //        String dayNow = new SimpleDateFormat("EEEE").format(now);
        Date beginScheduleDate;
        if (new SimpleDateFormat("ddMMyyyy").format(tanggalAkhirJadwal)
                .equals(new SimpleDateFormat("ddMMyyyy").format(new Date()))) {
            beginScheduleDate = DateTimeUtil.getDateFrom(startDate, (hasilBagi * num) - num,
                    CommonUtilConstant.DATE_FORMAT_DAY);
        } else {
            beginScheduleDate = DateTimeUtil.getDateFrom(startDate, (hasilBagi * num),
                    CommonUtilConstant.DATE_FORMAT_DAY);
        }

        List<TempJadwalKaryawan> dataToSave = new ArrayList<>();
        TempJadwalKaryawan jadwalKaryawan;
        for (Long id : dataEmpId) {
            //                dataToDelete.addAll(tempJadwalKaryawanDao.getAllByEmpId(id)); for bussiner process Sake so must be close
            List<WtScheduleShift> dataScheduleShift = new ArrayList<>(groupWorking.getWtScheduleShifts());
            //                Collections.sort(dataScheduleShift, shortByDate1);

            int totaldayPropsot = DateTimeUtil.getTotalDayDifference(startProposeDate, tanggalAkhirJadwal);

            int loop = totaldayPropsot / dataScheduleShift.size();
            List<WtScheduleShift> sortedDataScheduleShift = Lambda.sort(dataScheduleShift,
                    Lambda.on(WtScheduleShift.class).getScheduleDate());
            int i = 0;
            //                for (int a = 0; a < loop; a++) {
            for (WtScheduleShift wtScheduleShift : sortedDataScheduleShift) {
                String onlyDate = new SimpleDateFormat("yyyy-MM-dd").format(
                        DateTimeUtil.getDateFrom(beginScheduleDate, i, CommonUtilConstant.DATE_FORMAT_DAY));
                Date olnyDate = new SimpleDateFormat("yyyy-MM-dd").parse(onlyDate);

                jadwalKaryawan = tempJadwalKaryawanDao.getByEmpId(id, olnyDate);
                if (jadwalKaryawan != null) {
                    jadwalKaryawan.setUpdatedBy(createBy);
                    jadwalKaryawan.setUpdatedOn(new Date());
                    //                jadwalKaryawan = tempJadwalKaryawanDao.getByEmpId(empData.getId(), olnyDate);
                } else {
                    jadwalKaryawan = new TempJadwalKaryawan();
                    jadwalKaryawan.setId(Long.parseLong(RandomNumberUtil.getRandomNumber(12)));
                    jadwalKaryawan.setEmpData(empDataDao.getEntiyByPK(id));
                    jadwalKaryawan.setTanggalWaktuKerja(
                            DateTimeUtil.getDateFrom(beginScheduleDate, i, CommonUtilConstant.DATE_FORMAT_DAY));
                    jadwalKaryawan.setCreatedBy(createBy);
                    jadwalKaryawan.setCreatedOn(createOn);

                }
                //                    TempJadwalKaryawan jadwalKaryawan = new TempJadwalKaryawan();
                //                    jadwalKaryawan.setEmpData(empDataDao.getEntiyByPK(id));
                //                    jadwalKaryawan.setTanggalWaktuKerja(DateTimeUtil.getDateFrom(beginScheduleDate, i, CommonUtilConstant.DATE_FORMAT_DAY));
                //                    jadwalKaryawan.setWtWorkingHour(wtScheduleShift.getWtWorkingHour());
                WtHoliday holiday = wtHolidayDao.getWtHolidayByDate(jadwalKaryawan.getTanggalWaktuKerja());
                if (holiday != null && groupWorking.getTypeSequeace().equals(HRMConstant.NORMAL_SCHEDULE)) {
                    jadwalKaryawan.setWtWorkingHour(wtWorkingHourDao.getByCode("OFF"));
                } else {
                    jadwalKaryawan.setWtWorkingHour(wtScheduleShift.getWtWorkingHour());
                }
                //                    WtHoliday holiday = wtHolidayDao.getWtHolidayByDate(jadwalKaryawan.getTanggalWaktuKerja());
                //                    if (holiday != null || wtScheduleShift.getWtWorkingHour().getCode().equalsIgnoreCase("OFF")) {
                //                        jadwalKaryawan.setAttendanceStatus(attendanceStatusDao.getByCode("OFF"));
                //                    } else {
                //                        jadwalKaryawan.setAttendanceStatus(attendanceStatusDao.getByCode("HD1"));
                //                    }
                jadwalKaryawan.setIsCollectiveLeave(Boolean.FALSE);
                Date jadwal = jadwalKaryawan.getTanggalWaktuKerja();
                if (jadwal.equals(startProposeDate) || jadwal.equals(tanggalAkhirJadwal)) {
                    dataToSave.add(jadwalKaryawan);
                }
                if ((jadwal.after(startProposeDate) && jadwal.before(tanggalAkhirJadwal))) {
                    dataToSave.add(jadwalKaryawan);
                }
                i++;
            }
            //                }
        }
        //            tempJadwalKaryawanDao.deleteBacth(dataToDelete);
        tempJadwalKaryawanDao.saveBatch(dataToSave);

        //sending email process
        //            this.sendingEmailJadwalKaryawan(dataToSave, jSONObject.getString("locale"));
    } catch (Exception ex) {
        LOGGER.error("Error", ex);
    }
}

From source file:net.spfbl.whois.Handle.java

/**
 * Altera a data de allterao do registro.
 * @param changed a nova data de alterao do registro.
 * @throws ProcessException se houver falha no processamento.
 *///  w  w w .j  a v a 2s.co m
public void setChanged(String changed) throws ProcessException {
    if (changed == null) {
        throw new ProcessException("ERROR: CREATED CHANGED");
    } else if (changed.length() == 0) {
        if (this.changed != null) {
            this.changed = null;
            // Atualiza flag de atualizao.
            CHANGED = true;
        }
    } else {
        try {
            Date changedDate = DATE_FORMATTER.parse(changed);
            if (!changedDate.equals(this.changed)) {
                this.changed = changedDate;
                // Atualiza flag de atualizao.
                CHANGED = true;
            }
        } catch (ParseException ex) {
            Server.logError(ex);
            throw new ProcessException("ERROR: PARSING CHANGED " + changed);
        }
    }
}

From source file:org.jasig.schedassist.model.AvailableBlock.java

/**
 * //w w  w  . j  a v a 2 s . c  om
 * @param startTime
 * @param endTime
 * @param visitorLimit
 * @param meetingLocation
 * @throws IllegalArgumentException if startTime/endTime are null, or if endTime is before or equal to startTime, or if visitorLimit is less than 1 
 */
AvailableBlock(final Date startTime, final Date endTime, final int visitorLimit, String meetingLocation) {
    Validate.notNull(startTime, "startTime cannot be null");
    Validate.notNull(endTime, "endTime cannot be null");
    if (endTime.before(startTime) || endTime.equals(startTime)) {
        throw new IllegalArgumentException(
                "startTime (" + startTime + ") must precede endTime (" + endTime + ")");
    }
    if (visitorLimit < 1) {
        throw new IllegalArgumentException("visitorLimit must be greater than or equal to 1: " + visitorLimit);
    }
    this.startTime = DateUtils.truncate(startTime, Calendar.MINUTE);
    this.endTime = DateUtils.truncate(endTime, Calendar.MINUTE);
    this.visitorLimit = visitorLimit;
    this.meetingLocation = meetingLocation;
}

From source file:org.jfree.data.time.DayTest.java

/**
 * Problem for date parsing./*www .  jav  a  2 s  .  c  o  m*/
 * <p>
 * This test works only correct if the short pattern of the date
 * format is "dd/MM/yyyy". If not, this test will result in a
 * false negative.
 *
 * @throws ParseException on parsing errors.
 */
@Test
public void testParseDay() throws ParseException {
    GregorianCalendar gc = new GregorianCalendar(2001, 12, 31);
    SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
    Date reference = format.parse("31/12/2001");
    if (reference.equals(gc.getTime())) {
        // test 1...
        Day d = Day.parseDay("31/12/2001");
        assertEquals(37256, d.getSerialDate().toSerial());
    }

    // test 2...
    Day d = Day.parseDay("2001-12-31");
    assertEquals(37256, d.getSerialDate().toSerial());
}

From source file:net.sourceforge.vulcan.git.CommitLogParserTest.java

public void testParseTimestampInDifferentTimeZone() throws Exception {
    final LogEntryDateParseRule rule = new LogEntryDateParseRule();
    final Date d1 = rule.parse("2012-01-31T23:59:42-08:30");
    final Date d2 = rule.parse("2012-01-31T23:59:42-05:00");

    final long timeZoneDelta = (DateUtils.MILLIS_PER_HOUR * 3) + DateUtils.MILLIS_PER_MINUTE * 30;

    assertEquals(Long.toString(timeZoneDelta), Long.toString(d1.getTime() - d2.getTime()));

    assertFalse(d1.equals(d2));
}

From source file:org.kuali.mobility.events.service.EventsServiceImpl.java

@GET
@Deprecated/*  w w  w.  j a v a  2s.  co  m*/
@Path("/current/{campus}/{categoryId}")
@Override
public List<EventImpl> getAllEventsByDateCurrent(@QueryParam(value = "campus") String campus,
        @QueryParam(value = "categoryId") String categoryId,
        @QueryParam(value = "mon-dd-yy") Date dateCurrent) {

    List<EventImpl> events = getAllEvents(campus, categoryId);
    List<Event> resultEvents = new ArrayList<Event>();
    Iterator it = events.iterator();
    while (it.hasNext()) {
        Event obj = (Event) it.next();
        Date obtainedDate = obj.getStartDate();
        if (obtainedDate.equals(dateCurrent)) {
            resultEvents.add(obj);
        }

    }

    List<EventImpl> resultEventObjs = new ArrayList<EventImpl>();
    CollectionUtils.collect(resultEvents, new EventTransform(), resultEventObjs);

    return resultEventObjs;
}