List of usage examples for java.util GregorianCalendar setTime
public final void setTime(Date date)
Date
. From source file:ca.uhn.hl7v2.model.primitive.tests.CommonTMTest.java
@Test public void testToHl7TMFormat() throws DataTypeException, ParseException { //new tests related to bug 1173074 ... //case 1: Paris time, date in winter java.util.Date date = new SimpleDateFormat("yyyyMMddHHmmssZ").parse("19950305000000+0000"); GregorianCalendar cal = new GregorianCalendar(); cal.setTimeZone(TimeZone.getTimeZone("Europe/Paris")); cal.setTime(date); assertEquals("19950305010000+0100", CommonDT.toHl7DTFormat(cal) + CommonTM.toHl7TMFormat(cal)); //case 2: Paris time, date in summer date = new SimpleDateFormat("yyyyMMddHHmmssZ").parse("19950805000000+0000"); cal = new GregorianCalendar(); cal.setTimeZone(TimeZone.getTimeZone("Europe/Paris")); cal.setTime(date);/* w ww .j a v a 2s . co m*/ assertEquals("19950805020000+0200", CommonDT.toHl7DTFormat(cal) + CommonTM.toHl7TMFormat(cal)); //case 3: New York time, date in winter date = new SimpleDateFormat("yyyyMMddHHmmssZ").parse("19950305000000+0000"); cal = new GregorianCalendar(); cal.setTimeZone(TimeZone.getTimeZone("America/New_York")); cal.setTime(date); assertEquals("19950304190000-0500", CommonDT.toHl7DTFormat(cal) + CommonTM.toHl7TMFormat(cal)); //case 4: New York time, date in summer date = new SimpleDateFormat("yyyyMMddHHmmssZ").parse("19950805000000+0000"); cal = new GregorianCalendar(); cal.setTimeZone(TimeZone.getTimeZone("America/New_York")); cal.setTime(date); assertEquals("19950804200000-0400", CommonDT.toHl7DTFormat(cal) + CommonTM.toHl7TMFormat(cal)); }
From source file:mekhq.Utilities.java
public static int getDiffPartialYears(Date date, GregorianCalendar b) { GregorianCalendar a = new GregorianCalendar(); a.setTime(date); int diff = b.get(GregorianCalendar.YEAR) - a.get(GregorianCalendar.YEAR); if (diff == 0 && countDaysBetween(a.getTime(), b.getTime()) > 0) { return 1; }/* ww w . j a v a 2 s . c o m*/ return diff; }
From source file:mekhq.Utilities.java
public static int getDiffFullYears(Date date, GregorianCalendar b) { GregorianCalendar a = new GregorianCalendar(); a.setTime(date); int diff = b.get(GregorianCalendar.YEAR) - a.get(GregorianCalendar.YEAR); if (a.get(GregorianCalendar.MONTH) > b.get(GregorianCalendar.MONTH) || (a.get(GregorianCalendar.MONTH) == b.get(GregorianCalendar.MONTH) && a.get(GregorianCalendar.DATE) > b.get(GregorianCalendar.DATE))) { diff--;/*from w w w .j a va 2 s . c o m*/ } return diff; }
From source file:org.flowable.job.service.impl.asyncexecutor.DefaultJobManager.java
protected void internalCreateLockedAsyncJob(JobEntity jobEntity, boolean exclusive) { fillDefaultAsyncJobInfo(jobEntity, exclusive); GregorianCalendar gregorianCalendar = new GregorianCalendar(); gregorianCalendar.setTime(jobServiceConfiguration.getClock().getCurrentTime()); gregorianCalendar.add(Calendar.MILLISECOND, getAsyncExecutor().getAsyncJobLockTimeInMillis()); jobEntity.setLockExpirationTime(gregorianCalendar.getTime()); jobEntity.setLockOwner(getAsyncExecutor().getLockOwner()); }
From source file:org.flowable.job.service.impl.asyncexecutor.DefaultJobManager.java
protected JobEntity createExecutableJobFromOtherJob(AbstractRuntimeJobEntity job) { JobEntity executableJob = jobServiceConfiguration.getJobEntityManager().create(); copyJobInfo(executableJob, job);//from w ww . java2s .co m if (isAsyncExecutorActive()) { GregorianCalendar gregorianCalendar = new GregorianCalendar(); gregorianCalendar.setTime(jobServiceConfiguration.getClock().getCurrentTime()); gregorianCalendar.add(Calendar.MILLISECOND, getAsyncExecutor().getTimerLockTimeInMillis()); executableJob.setLockExpirationTime(gregorianCalendar.getTime()); executableJob.setLockOwner(getAsyncExecutor().getLockOwner()); } return executableJob; }
From source file:org.cesecore.util.PKIXCertRevocationStatusChecker.java
private boolean isCorrectCRL(final CRL crl, final String issuerDN) { if (!(crl instanceof X509CRL)) { return false; }// w w w . j a v a2 s. c om X509CRL x509crl = (X509CRL) crl; if (!StringUtils.equals(issuerDN, CertTools.getIssuerDN(x509crl))) { return false; } final Date now = new Date(System.currentTimeMillis()); final Date nextUpdate = x509crl.getNextUpdate(); if (nextUpdate != null) { if (nextUpdate.after(now)) { return true; } if (log.isDebugEnabled()) { log.debug("CRL issued by " + issuerDN + " is out of date"); } return false; } final Date thisUpdate = x509crl.getThisUpdate(); if (thisUpdate != null) { final GregorianCalendar gc = new GregorianCalendar(); gc.setTime(now); gc.add(Calendar.HOUR, 1); final Date expire = gc.getTime(); if (expire.before(now)) { if (log.isDebugEnabled()) { log.debug("Could not find when CRL issued by " + issuerDN + " should be updated and this CRL is over one hour old. Not using it"); } return false; } log.warn("Could not find when CRL issued by " + issuerDN + " should be updated, but this CRL was issued less than an hour ago, so we are using it"); return true; } if (log.isDebugEnabled()) { log.debug("Could not check issuance time for CRL issued by " + issuerDN); } return false; }
From source file:edu.stanford.muse.index.IndexUtils.java
public static List<MultiDoc> partitionDocsByInterval(Collection<? extends DatedDocument> allDocs, boolean monthsNotYears) { List<MultiDoc> result = new ArrayList<MultiDoc>(); if (allDocs.size() == 0) return result; Pair<Date, Date> p = EmailUtils.getFirstLast(allDocs); Date first = p.getFirst();/*from ww w . j a v a 2 s. co m*/ Date last = p.getSecond(); // compute the monthly intervals List<Date> intervals; if (monthsNotYears) intervals = Util.getMonthlyIntervals(first, last); else intervals = Util.getYearlyIntervals(first, last); int nIntervals = intervals.size() - 1; for (int i = 0; i < nIntervals; i++) { String clusterDescription; Date d = intervals.get(i); GregorianCalendar c = new GregorianCalendar(); c.setTime(d); if (!monthsNotYears) clusterDescription = Integer.toString(c.get(Calendar.YEAR)); else clusterDescription = CalendarUtil.getDisplayMonth(c) + " " + c.get(Calendar.YEAR); result.add(new MultiDoc(i, clusterDescription)); } for (DatedDocument ed : allDocs) { // find which interval this email belongs to int selectedInterval = -1; // TODO: if all this API does is either partition by month or year then no need to "search". Date c = ed.date; for (int i = 0; i < nIntervals; i++) { Date intervalStart = intervals.get(i); Date intervalEnd = intervals.get(i + 1); if (!c.before(intervalStart) && c.before(intervalEnd)) { selectedInterval = i; break; } } // this doc goes into interval # selectedInterval MultiDoc whichList = result.get(selectedInterval); whichList.add(ed); } return result; }
From source file:org.webical.test.web.component.WeekViewPanelTest.java
public void testWithoutEvents() { annotApplicationContextMock.putBean("eventManager", new MockEventManager()); final GregorianCalendar currentDate = CalendarUtils.newTodayCalendar(getFirstDayOfWeek()); // Create test page with a WeekViewPanel wicketTester.startPage(new ITestPageSource() { private static final long serialVersionUID = 1L; public Page getTestPage() { return new PanelTestPage(new WeekViewPanel(PanelTestPage.PANEL_MARKUP_ID, 7, currentDate) { private static final long serialVersionUID = 1L; @Override//from w ww . ja v a 2 s. c o m public void onAction(IAction action) { /* NOTHING TO DO */ } }); } }); // Basic assertions wicketTester.assertRenderedPage(PanelTestPage.class); wicketTester.assertComponent(PanelTestPage.PANEL_MARKUP_ID, WeekViewPanel.class); // Assert number of days rendered GregorianCalendar weekFirstDayCalendar = CalendarUtils.duplicateCalendar(currentDate); weekFirstDayCalendar.setTime(CalendarUtils.getFirstDayOfWeek(currentDate.getTime(), getFirstDayOfWeek())); // Assert the first day in the view wicketTester.assertComponent(PanelTestPage.PANEL_MARKUP_ID + ":weekColumnRepeater:day" + weekFirstDayCalendar.get(GregorianCalendar.DAY_OF_YEAR), WeekDayPanel.class); GregorianCalendar weekLastDayCalendar = CalendarUtils.duplicateCalendar(currentDate); weekLastDayCalendar.setTime(CalendarUtils.getLastDayOfWeek(currentDate.getTime(), getFirstDayOfWeek())); // Assert the last day in the view wicketTester.assertComponent(PanelTestPage.PANEL_MARKUP_ID + ":weekColumnRepeater:day" + weekLastDayCalendar.get(GregorianCalendar.DAY_OF_YEAR), WeekDayPanel.class); // Assert the heading label DateFormat dateFormat = new SimpleDateFormat("E", getTestSession().getLocale()); GregorianCalendar weekCal = CalendarUtils.duplicateCalendar(currentDate); weekCal.setTime(CalendarUtils.getFirstDayOfWeek(currentDate.getTime(), getFirstDayOfWeek())); for (int i = 0; i < 7; ++i) { wicketTester.assertLabel(PanelTestPage.PANEL_MARKUP_ID + ":dayHeadingRepeater:headerDay" + i, dateFormat.format(weekCal.getTime())); weekCal.add(GregorianCalendar.DAY_OF_WEEK, 1); } }
From source file:edu.umm.radonc.ca_dash.model.TxInstanceFacade.java
public SynchronizedDescriptiveStatistics getDailyStats(Date startDate, Date endDate, Long hospital, String filter, boolean includeWeekends, boolean ptflag, boolean scheduledFlag) { SynchronizedDescriptiveStatistics stats = new SynchronizedDescriptiveStatistics(); GregorianCalendar gc = new GregorianCalendar(); gc.setTime(endDate); gc.add(Calendar.DATE, -1);//w w w. j ava2 s . c o m List<Object[]> counts = getDailyCounts(startDate, gc.getTime(), hospital, filter, includeWeekends, ptflag, scheduledFlag); for (Object[] item : counts) { stats.addValue(((Long) item[1]).doubleValue()); } return stats; }
From source file:edu.umm.radonc.ca_dash.model.TxInstanceFacade.java
public Map<Date, SynchronizedDescriptiveStatistics> getWeeklyTrailingSummaryStats(Date startDate, Date endDate, Long hospitalser, String filter, boolean includeWeekends, boolean ptflag, boolean scheduledFlag) { TreeMap<Date, SynchronizedDescriptiveStatistics> retval = new TreeMap(); GregorianCalendar gc = new GregorianCalendar(); gc.setTime(endDate); Date d;//w ww . j a v a 2 s . c om SynchronizedDescriptiveStatistics stats; while (gc.getTime().compareTo(startDate) > 0) { d = gc.getTime(); gc.add(Calendar.DATE, -7); stats = getDailyStats(gc.getTime(), d, hospitalser, filter, includeWeekends, ptflag, scheduledFlag); retval.put(gc.getTime(), stats); } return retval; }