List of usage examples for java.util Date equals
public boolean equals(Object obj)
From source file:org.apache.falcon.workflow.engine.OozieWorkflowEngine.java
private void change(String cluster, String id, int concurrency, Date endTime, String pauseTime) throws FalconException { StringBuilder changeValue = new StringBuilder(); changeValue.append(OozieClient.CHANGE_VALUE_CONCURRENCY).append("=").append(concurrency).append(";"); if (endTime != null) { String endTimeStr = SchemaHelper.formatDateUTC(endTime); changeValue.append(OozieClient.CHANGE_VALUE_ENDTIME).append("=").append(endTimeStr).append(";"); }//from w w w.j a v a 2 s . c om if (pauseTime != null) { changeValue.append(OozieClient.CHANGE_VALUE_PAUSETIME).append("=").append(pauseTime); } String changeValueStr = changeValue.toString(); if (changeValue.toString().endsWith(";")) { changeValueStr = changeValue.substring(0, changeValueStr.length() - 1); } change(cluster, id, changeValueStr); // assert that its really changed try { OozieClient client = OozieClientFactory.get(cluster); CoordinatorJob coord = client.getCoordJobInfo(id); for (int counter = 0; counter < 3; counter++) { Date intendedPauseTime = (StringUtils.isEmpty(pauseTime) ? null : SchemaHelper.parseDateUTC(pauseTime)); if (coord.getConcurrency() != concurrency || (endTime != null && !coord.getEndTime().equals(endTime)) || (intendedPauseTime != null && !intendedPauseTime.equals(coord.getPauseTime()))) { try { Thread.sleep(100); } catch (InterruptedException ignore) { //ignore } } else { return; } coord = client.getCoordJobInfo(id); } LOG.error("Failed to change coordinator. Current value {}, {}, {}", coord.getConcurrency(), SchemaHelper.formatDateUTC(coord.getEndTime()), SchemaHelper.formatDateUTC(coord.getPauseTime())); throw new FalconException( "Failed to change coordinator " + id + " with change value " + changeValueStr); } catch (OozieClientException e) { throw new FalconException(e); } }
From source file:com.krawler.esp.servlets.importProjectPlanCSV.java
/** * Establish predecessor and successors. checks for * 1. inconsistent start and finish dates for pred-succ * 2. finding the specified task in imported data */// w ww .java2s .co m private int savePredecessors(Connection conn, int errorCount) throws ServiceException { String fromtaskid = "", totaskid = ""; java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-d"); DbResults rs = DbUtil.executeQuery(conn, "SELECT taskid, predecessor FROM tempImportData"); while (rs.next()) { try { totaskid = rs.getString("taskid"); String pred = rs.getString("predecessor"); if (!StringUtil.equal(pred, "")) { String predsearr[] = pred.split(","); for (int i = 0; i < predsearr.length; i++) { DbResults rs1 = DbUtil.executeQuery(conn, "SELECT taskid, duration FROM tempImportData WHERE taskindex = ?", new Object[] { predsearr[i] }); if (rs1.next()) { fromtaskid = rs1.getString("taskid"); double duration = projdb.getDuration(rs1.getString("duration")); Date sd = null, ed = null; DbResults to = DbUtil.executeQuery(conn, "SELECT startdate FROM proj_task WHERE taskid = ?", totaskid); if (to.next()) sd = sdf.parse(to.getObject("startdate").toString()); DbResults from = DbUtil.executeQuery(conn, "SELECT enddate FROM proj_task WHERE taskid = ?", fromtaskid); if (from.next()) ed = sdf.parse(from.getObject("enddate").toString()); if (sd != null && ed != null) { if ((sd.after(ed) && duration != 0) || ((sd.after(ed) || sd.equals(ed)) && duration == 0)) { projdb.addLink(conn, fromtaskid, totaskid); } else { ImportLogHandler.updateTaskLog(conn, totaskid, KWLErrorMsgs.iLPredInvalidDate); errorCount++; } } else { ImportLogHandler.updateTaskLog(conn, totaskid, KWLErrorMsgs.iLPredInvalidDate); errorCount++; } } else { // taskindex doesnt exist in tempImportData ImportLogHandler.updateTaskLog(conn, totaskid, KWLErrorMsgs.iLPredNotFound); errorCount++; } } } } catch (ParseException ex) { ImportLogHandler.updateTaskLog(conn, totaskid, KWLErrorMsgs.iLExPred); errorCount++; } catch (ServiceException ex) { ImportLogHandler.updateTaskLog(conn, totaskid, KWLErrorMsgs.iLExPred); errorCount++; } } return errorCount; }
From source file:org.eclipse.smarthome.core.scheduler.RecurrenceExpression.java
@Override public boolean isSatisfiedBy(final Date test) { getTimeAfter(test);//from w w w . j a va 2 s . c o m Collections.sort(getCandidates()); for (Date aDate : getCandidates()) { if (aDate.after(test)) { return false; } if (aDate.equals(test)) { return true; } } return false; }
From source file:ch.entwine.weblounge.test.harness.content.CacheTest.java
/** * Test if the cache is returning proper header to enable caching on the * client side, such as <code>Last-Modified</code>, <code>Expires</code> or * <code>ETag</code>./* w w w.j a v a 2 s .c om*/ * * @param serverUrl * the server url * @throws Exception * if the test fails */ private void testCacheHeaders(String serverUrl) throws Exception { logger.info("Preparing test of response caching"); DateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US); df.setTimeZone(TimeZone.getTimeZone("GMT")); // Prepare the request logger.info("Testing response cache"); String requestUrl = UrlUtils.concat(serverUrl, contentTestPage, language.getIdentifier()); logger.info("Sending request to the {} version of {}", language.getLocale().getDisplayName(), requestUrl); HttpGet request = new HttpGet(requestUrl); request.addHeader("X-Cache-Debug", "yes"); String[][] params = new String[][] { { "language", language.getIdentifier() } }; // Send and the request and examine the response. The first request might // not come out of the cache logger.debug("Sending request to {}", request.getURI()); HttpClient httpClient = new DefaultHttpClient(); try { HttpResponse response = TestUtils.request(httpClient, request, params); int statusCode = response.getStatusLine().getStatusCode(); boolean okOrNotModified = statusCode == HttpServletResponse.SC_OK || statusCode == HttpServletResponse.SC_NOT_MODIFIED; assertTrue(okOrNotModified); // Get the ETag header assertNotNull(response.getHeaders("ETag")); assertEquals(1, response.getHeaders("ETag").length); String eTag = response.getHeaders("ETag")[0].getValue(); // Get the Expires header assertNotNull(response.getHeaders("Expires")); assertEquals(1, response.getHeaders("Expires").length); Date expires = df.parse(response.getHeaders("Expires")[0].getValue()); // Prepare the second request response.getEntity().consumeContent(); httpClient.getConnectionManager().shutdown(); // Give the cache time to persist the entry Thread.sleep(1000); httpClient = new DefaultHttpClient(); request.setHeader("If-None-Match", eTag); request.setHeader("If-Modified-Since", df.format(System.currentTimeMillis())); response = TestUtils.request(httpClient, request, params); assertEquals(HttpServletResponse.SC_NOT_MODIFIED, response.getStatusLine().getStatusCode()); // Get the Expires header assertNotNull(response.getHeaders("Expires")); assertEquals(1, response.getHeaders("Expires").length); // We are explicitly not checking for equality with the previously // received value, since on first request, that value is not yet correct // Get the ETag header assertNotNull(response.getHeaders("ETag")); assertEquals(0, response.getHeaders("ETag").length); // Test the Cache header assertNotNull(response.getHeaders("X-Cache-Key")); assertEquals(1, response.getHeaders("X-Cache-Key").length); // Test the expires header Date newExpires = df.parse(response.getHeaders("Expires")[0].getValue()); assertTrue(expires.before(newExpires) || expires.equals(newExpires)); } finally { httpClient.getConnectionManager().shutdown(); } }
From source file:de.hybris.platform.servicelayer.tx.ItemModelTransactionTest.java
@Test public void testModificationTimeUpdateOutsideTx() throws Exception { final MediaModel media = setupMedia("cat", "media", MIME_BEFORE); final Media jaloMedia = modelService.getSource(media); final PK mediaPK = media.getPk(); assertEquals(mediaPK, jaloMedia.getPK()); final Date modModelBefore = media.getModifiedtime(); final Date modJaloBefore = jaloMedia.getModificationTime(); assertNotNull(modModelBefore);//from w w w . j a v a 2 s . com assertNotNull(modJaloBefore); assertEquals(modJaloBefore, modModelBefore); Thread.sleep(1500); // Some DB (MySql) do not have milliseconds! final Transaction tx = Transaction.current(); tx.execute(new TransactionBody() { @Override public Object execute() throws Exception { // Attention: we MUST read the media at least once to attach it to this // transaction. Otherwise we'd see the outside change as legal COMMITTED // state! final Date modJaloInTxBefore = jaloMedia.getModificationTime(); assertNotNull(modJaloInTxBefore); assertEquals(modJaloBefore, modJaloInTxBefore); final Date modJaloOutside = changeMimeInOtherThread(mediaPK, MIME_AFTER); final Date modModelAfter = media.getModifiedtime(); final Date modJaloAfter = jaloMedia.getModificationTime(); assertNotNull(modModelAfter); assertNotNull(modJaloAfter); assertNotNull(modJaloOutside); assertFalse("tx can see mod time from outside tx (expected " + modJaloBefore.getTime() + " but got " + modJaloAfter.getTime(), modJaloOutside.equals(modJaloAfter)); assertEquals(modModelAfter.getTime(), modJaloAfter.getTime()); assertEquals(modJaloBefore.getTime(), modJaloAfter.getTime()); assertEquals(modModelBefore.getTime(), modModelAfter.getTime()); return null; } }); modelService.refresh(media); // actually not necessary but more likely to find error final Date modModelAfterTx = media.getModifiedtime(); final Date modJaloAfterTx = jaloMedia.getModificationTime(); assertNotNull(modModelAfterTx); assertNotNull(modJaloAfterTx); assertEquals(modModelAfterTx, modJaloAfterTx); assertTrue(modJaloBefore.before(modJaloAfterTx)); }
From source file:ca.uhn.fhir.jpa.dao.BaseHapiFhirDao.java
@SuppressWarnings("unchecked") private <R extends IBaseResource> R populateResourceMetadataRi(Class<R> theResourceType, BaseHasResource theEntity, boolean theForHistoryOperation, IAnyResource res) { R retVal = (R) res;/*from www . ja v a 2 s . c o m*/ if (theEntity.getDeleted() != null) { res = (IAnyResource) myContext.getResourceDefinition(theResourceType).newInstance(); retVal = (R) res; ResourceMetadataKeyEnum.DELETED_AT.put(res, new InstantDt(theEntity.getDeleted())); if (theForHistoryOperation) { ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.put(res, HTTPVerb.DELETE.toCode()); } } else if (theForHistoryOperation) { /* * If the create and update times match, this was when the resource was created so we should mark it as a POST. Otherwise, it's a PUT. */ Date published = theEntity.getPublished().getValue(); Date updated = theEntity.getUpdated().getValue(); if (published.equals(updated)) { ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.put(res, HTTPVerb.POST.toCode()); } else { ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.put(res, HTTPVerb.PUT.toCode()); } } res.getMeta().getTag().clear(); res.getMeta().getProfile().clear(); res.getMeta().getSecurity().clear(); res.getMeta().setLastUpdated(null); res.getMeta().setVersionId(null); populateResourceId(res, theEntity); res.getMeta().setLastUpdated(theEntity.getUpdatedDate()); IDao.RESOURCE_PID.put(res, theEntity.getId()); Collection<? extends BaseTag> tags = theEntity.getTags(); if (theEntity.isHasTags()) { for (BaseTag next : tags) { switch (next.getTag().getTagType()) { case PROFILE: res.getMeta().addProfile(next.getTag().getCode()); break; case SECURITY_LABEL: IBaseCoding sec = res.getMeta().addSecurity(); sec.setSystem(next.getTag().getSystem()); sec.setCode(next.getTag().getCode()); sec.setDisplay(next.getTag().getDisplay()); break; case TAG: IBaseCoding tag = res.getMeta().addTag(); tag.setSystem(next.getTag().getSystem()); tag.setCode(next.getTag().getCode()); tag.setDisplay(next.getTag().getDisplay()); break; } } } return retVal; }
From source file:ca.uhn.fhir.jpa.dao.BaseHapiFhirDao.java
@SuppressWarnings("unchecked") private <R extends IBaseResource> R populateResourceMetadataHapi(Class<R> theResourceType, BaseHasResource theEntity, boolean theForHistoryOperation, IResource res) { R retVal = (R) res;//w w w .ja v a 2s .com if (theEntity.getDeleted() != null) { res = (IResource) myContext.getResourceDefinition(theResourceType).newInstance(); retVal = (R) res; ResourceMetadataKeyEnum.DELETED_AT.put(res, new InstantDt(theEntity.getDeleted())); if (theForHistoryOperation) { ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.put(res, BundleEntryTransactionMethodEnum.DELETE); } } else if (theForHistoryOperation) { /* * If the create and update times match, this was when the resource was created so we should mark it as a POST. Otherwise, it's a PUT. */ Date published = theEntity.getPublished().getValue(); Date updated = theEntity.getUpdated().getValue(); if (published.equals(updated)) { ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.put(res, BundleEntryTransactionMethodEnum.POST); } else { ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.put(res, BundleEntryTransactionMethodEnum.PUT); } } res.setId(theEntity.getIdDt()); ResourceMetadataKeyEnum.VERSION.put(res, Long.toString(theEntity.getVersion())); ResourceMetadataKeyEnum.PUBLISHED.put(res, theEntity.getPublished()); ResourceMetadataKeyEnum.UPDATED.put(res, theEntity.getUpdated()); IDao.RESOURCE_PID.put(res, theEntity.getId()); if (theEntity.getTitle() != null) { ResourceMetadataKeyEnum.TITLE.put(res, theEntity.getTitle()); } Collection<? extends BaseTag> tags = theEntity.getTags(); if (theEntity.isHasTags()) { TagList tagList = new TagList(); List<IBaseCoding> securityLabels = new ArrayList<IBaseCoding>(); List<IdDt> profiles = new ArrayList<IdDt>(); for (BaseTag next : tags) { switch (next.getTag().getTagType()) { case PROFILE: profiles.add(new IdDt(next.getTag().getCode())); break; case SECURITY_LABEL: IBaseCoding secLabel = (IBaseCoding) myContext.getVersion().newCodingDt(); secLabel.setSystem(next.getTag().getSystem()); secLabel.setCode(next.getTag().getCode()); secLabel.setDisplay(next.getTag().getDisplay()); securityLabels.add(secLabel); break; case TAG: tagList.add(new Tag(next.getTag().getSystem(), next.getTag().getCode(), next.getTag().getDisplay())); break; } } if (tagList.size() > 0) { ResourceMetadataKeyEnum.TAG_LIST.put(res, tagList); } if (securityLabels.size() > 0) { ResourceMetadataKeyEnum.SECURITY_LABELS.put(res, toBaseCodingList(securityLabels)); } if (profiles.size() > 0) { ResourceMetadataKeyEnum.PROFILES.put(res, profiles); } } return retVal; }
From source file:com.liferay.portal.security.ldap.internal.exportimport.LDAPUserImporterImpl.java
protected User updateUser(LDAPImportContext ldapImportContext, LDAPUser ldapUser, User user, String password, String modifyTimestamp, boolean isNew) throws Exception { StopWatch stopWatch = new StopWatch(); long companyId = ldapImportContext.getCompanyId(); long ldapServerId = ldapImportContext.getLdapServerId(); if (_log.isDebugEnabled()) { stopWatch.start();//from w ww . java2s. co m if (isNew) { _log.debug(StringBundler.concat("Updating new user ", String.valueOf(user), " from LDAP server ", String.valueOf(ldapServerId), " to company ", String.valueOf(companyId))); } else { _log.debug( StringBundler.concat("Updating existing user ", String.valueOf(user), " from LDAP server ", String.valueOf(ldapServerId), " to company ", String.valueOf(companyId))); } } Date modifiedDate = null; LDAPImportConfiguration ldapImportConfiguration = _ldapImportConfigurationProvider .getConfiguration(companyId); boolean passwordReset = ldapUser.isPasswordReset(); if (_ldapSettings.isExportEnabled(companyId)) { passwordReset = user.isPasswordReset(); } try { if (Validator.isNotNull(modifyTimestamp)) { modifiedDate = LDAPUtil.parseDate(modifyTimestamp); if (modifiedDate.equals(user.getModifiedDate())) { if (ldapUser.isUpdatePassword() || !ldapImportConfiguration.importUserPasswordEnabled()) { updateUserPassword(ldapImportConfiguration, user.getUserId(), user.getScreenName(), password, passwordReset); } if (_log.isDebugEnabled()) { _log.debug(StringBundler.concat("User ", user.getEmailAddress(), " is already synchronized, but updated ", "password to avoid a blank value")); } return user; } } else if (!isNew) { if (_log.isInfoEnabled()) { _log.info("Skipping user " + user.getEmailAddress() + " because the LDAP entry was never modified"); } return user; } } catch (ParseException pe) { if (_log.isDebugEnabled()) { _log.debug("Unable to parse LDAP modify timestamp " + modifyTimestamp, pe); } } LDAPServerConfiguration ldapServerConfiguration = _ldapServerConfigurationProvider .getConfiguration(companyId, ldapServerId); String[] userIgnoreAttributes = ldapServerConfiguration.userIgnoreAttributes(); Set<String> ldapUserIgnoreAttributes = new HashSet<>(Arrays.asList(userIgnoreAttributes)); if (Validator.isNull(ldapUser.getScreenName()) || ldapUser.isAutoScreenName()) { ldapUser.setScreenName(user.getScreenName()); } if (ldapUser.isUpdatePassword() || !ldapImportConfiguration.importUserPasswordEnabled()) { password = updateUserPassword(ldapImportConfiguration, user.getUserId(), ldapUser.getScreenName(), password, passwordReset); } Contact ldapContact = ldapUser.getContact(); updateLDAPUser(ldapUser.getUser(), ldapContact, user, ldapImportContext.getUserMappings(), ldapImportContext.getContactMappings(), ldapUserIgnoreAttributes); Calendar birthdayCal = CalendarFactoryUtil.getCalendar(); birthdayCal.setTime(ldapContact.getBirthday()); int birthdayMonth = birthdayCal.get(Calendar.MONTH); int birthdayDay = birthdayCal.get(Calendar.DAY_OF_MONTH); int birthdayYear = birthdayCal.get(Calendar.YEAR); user = _userLocalService.updateUser(user.getUserId(), password, StringPool.BLANK, StringPool.BLANK, passwordReset, ldapUser.getReminderQueryQuestion(), ldapUser.getReminderQueryAnswer(), ldapUser.getScreenName(), ldapUser.getEmailAddress(), ldapUser.getFacebookId(), ldapUser.getOpenId(), ldapUser.isUpdatePortrait(), ldapUser.getPortraitBytes(), ldapUser.getLanguageId(), ldapUser.getTimeZoneId(), ldapUser.getGreeting(), ldapUser.getComments(), ldapUser.getFirstName(), ldapUser.getMiddleName(), ldapUser.getLastName(), ldapUser.getPrefixId(), ldapUser.getSuffixId(), ldapUser.isMale(), birthdayMonth, birthdayDay, birthdayYear, ldapUser.getSmsSn(), ldapUser.getFacebookSn(), ldapUser.getJabberSn(), ldapUser.getSkypeSn(), ldapUser.getTwitterSn(), ldapUser.getJobTitle(), ldapUser.getGroupIds(), ldapUser.getOrganizationIds(), ldapUser.getRoleIds(), ldapUser.getUserGroupRoles(), ldapUser.getUserGroupIds(), ldapUser.getServiceContext()); ServiceContext serviceContext = new ServiceContext(); if (modifiedDate != null) { serviceContext.setModifiedDate(modifiedDate); } user = _userLocalService.updateStatus(user.getUserId(), ldapUser.getStatus(), serviceContext); if (_log.isDebugEnabled()) { _log.debug(StringBundler.concat("Finished update for user ", String.valueOf(user), " in ", String.valueOf(stopWatch.getTime()), "ms")); } return user; }
From source file:org.pentaho.di.trans.steps.scriptvalues_mod.ScriptValuesAddedFunctions.java
public static Object date2str(Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext) { Object oRC = new Object(); switch (ArgList.length) { case 0://from www . j a v a 2 s . c o m throw Context.reportRuntimeError("Please provide a valid date to the function call date2str."); case 1: try { if (isNull(ArgList)) { return null; } else if (isUndefined(ArgList)) { return Context.getUndefinedValue(); } java.util.Date dArg1 = (java.util.Date) Context.jsToJava(ArgList[0], java.util.Date.class); if (dArg1.equals(null)) { return null; } Format dfFormatter = new SimpleDateFormat(); oRC = dfFormatter.format(dArg1); } catch (Exception e) { throw Context.reportRuntimeError("Could not convert to local format."); } break; case 2: try { if (isNull(ArgList, new int[] { 0, 1 })) { return null; } else if (isUndefined(ArgList, new int[] { 0, 1 })) { return Context.getUndefinedValue(); } java.util.Date dArg1 = (java.util.Date) Context.jsToJava(ArgList[0], java.util.Date.class); String sArg2 = Context.toString(ArgList[1]); Format dfFormatter = new SimpleDateFormat(sArg2); oRC = dfFormatter.format(dArg1); } catch (Exception e) { throw Context.reportRuntimeError("Could not convert to the given format."); } break; case 3: try { if (isNull(ArgList, new int[] { 0, 1, 2 })) { return null; } else if (isUndefined(ArgList, new int[] { 0, 1, 2 })) { return Context.getUndefinedValue(); } java.util.Date dArg1 = (java.util.Date) Context.jsToJava(ArgList[0], java.util.Date.class); DateFormat dfFormatter; String sArg2 = Context.toString(ArgList[1]); String sArg3 = Context.toString(ArgList[2]); if (sArg3.length() == 2) { Locale dfLocale = EnvUtil.createLocale(sArg3.toLowerCase()); dfFormatter = new SimpleDateFormat(sArg2, dfLocale); oRC = dfFormatter.format(dArg1); } else { throw Context.reportRuntimeError("Locale is not 2 characters long."); } } catch (Exception e) { throw Context.reportRuntimeError("Could not convert to the given local format."); } break; case 4: try { if (isNull(ArgList, new int[] { 0, 1, 2, 3 })) { return null; } else if (isUndefined(ArgList, new int[] { 0, 1, 2, 3 })) { return Context.getUndefinedValue(); } java.util.Date dArg1 = (java.util.Date) Context.jsToJava(ArgList[0], java.util.Date.class); DateFormat dfFormatter; String sArg2 = Context.toString(ArgList[1]); String sArg3 = Context.toString(ArgList[2]); String sArg4 = Context.toString(ArgList[3]); // If the timezone is not recognized, java will automatically // take GMT. TimeZone tz = TimeZone.getTimeZone(sArg4); if (sArg3.length() == 2) { Locale dfLocale = EnvUtil.createLocale(sArg3.toLowerCase()); dfFormatter = new SimpleDateFormat(sArg2, dfLocale); dfFormatter.setTimeZone(tz); oRC = dfFormatter.format(dArg1); } else { throw Context.reportRuntimeError("Locale is not 2 characters long."); } } catch (Exception e) { throw Context.reportRuntimeError("Could not convert to the given local format."); } break; default: throw Context.reportRuntimeError("The function call date2str requires 1, 2, 3, or 4 arguments."); } return oRC; }
From source file:vn.com.ecopharma.emp.service.impl.EmpLocalServiceImpl.java
public boolean isSameOrWrongOrderDoB(Date empDob, Date userEmpDob) { if (empDob == null || userEmpDob == null) return false; if (empDob.equals(userEmpDob)) return true; // Next, check if user enter wrong format because of locale's setting // example: 12/02/2015 means Dec 02 2015 but the user think that it was // 12 Feb 2015 boolean isReverseMonthEqual = false; boolean isReverseDayEqual = false; final Calendar calendar = Calendar.getInstance(); calendar.setTime(empDob);//from w ww .j a v a 2 s . c om int empDobDay = calendar.get(Calendar.DAY_OF_MONTH); int empDobMonth = calendar.get(Calendar.MONTH) + 1; int empDobYear = calendar.get(Calendar.YEAR); calendar.setTime(userEmpDob); int userEmpDobDay = calendar.get(Calendar.DAY_OF_MONTH); int userEmpDobMonth = calendar.get(Calendar.MONTH) + 1; int userEmpDobYear = calendar.get(Calendar.YEAR); if (empDobYear != userEmpDobYear) return false; isReverseMonthEqual = empDobMonth == userEmpDobDay; isReverseDayEqual = empDobDay == userEmpDobMonth; return isReverseMonthEqual && isReverseDayEqual; }