List of usage examples for java.util GregorianCalendar set
public final void set(int year, int month, int date, int hourOfDay, int minute, int second)
YEAR
, MONTH
, DAY_OF_MONTH
, HOUR_OF_DAY
, MINUTE
, and SECOND
. From source file:com.anite.zebra.hivemind.impl.TimedTaskRunnerImpl.java
private boolean isTaskDueToday(TimedTask timedTask) { boolean taskOK = false; Calendar calendar = Calendar.getInstance(); GregorianCalendar now = new GregorianCalendar(); now.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), 23, 59, 59);//from ww w. ja v a 2 s . c om Date lastThingToday = new Date(now.getTimeInMillis()); if (timedTask.getRunTaskDate() == null || timedTask.getRunTaskDate().equals(lastThingToday) || timedTask.getRunTaskDate().before(lastThingToday)) { taskOK = true; } return taskOK; }
From source file:org.apache.eagle.jpm.mr.history.crawler.JHFCrawlerDriverImpl.java
private void advanceOneDay() throws Exception { //flushJobCount(); GregorianCalendar cal = new GregorianCalendar(timeZone); cal.set(this.processDate.year, this.processDate.month, this.processDate.day, 0, 0, 0); cal.add(Calendar.DATE, 1);// w w w .j ava 2s .co m this.processDate.year = cal.get(Calendar.YEAR); this.processDate.month = cal.get(Calendar.MONTH); this.processDate.day = cal.get(Calendar.DAY_OF_MONTH); try { clearProcessedJob(cal); } catch (Exception e) { LOG.error("failed to clear processed job ", e); } }
From source file:org.apache.eagle.jpm.mr.history.crawler.JHFCrawlerDriverImpl.java
private void readAndCacheLastProcessedDate() throws Exception { String lastProcessedDate = JobHistoryZKStateManager.instance().readProcessedDate(partitionId); Matcher m = PATTERN_JOB_PROCESS_DATE.matcher(lastProcessedDate); if (m.find() && m.groupCount() == 3) { this.processDate.year = Integer.parseInt(m.group(1)); this.processDate.month = Integer.parseInt(m.group(2)) - 1; // zero based month this.processDate.day = Integer.parseInt(m.group(3)); } else {/* w w w .j a v a2 s . c o m*/ throw new IllegalStateException("job lastProcessedDate must have format YYYYMMDD " + lastProcessedDate); } GregorianCalendar cal = new GregorianCalendar(timeZone); cal.set(this.processDate.year, this.processDate.month, this.processDate.day, 0, 0, 0); cal.add(Calendar.DATE, 1); List<String> list = JobHistoryZKStateManager.instance() .readProcessedJobs(String.format(FORMAT_JOB_PROCESS_DATE, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH))); if (list != null) { this.processedJobFileNames = new HashSet<>(list); } }
From source file:org.jfree.data.time.WeekTest.java
/** * A test case for bug 1498805./* w w w.j a va 2s. co m*/ */ @Test public void testBug1498805() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); try { TimeZone zone = TimeZone.getTimeZone("GMT"); GregorianCalendar gc = new GregorianCalendar(zone); gc.set(2005, Calendar.JANUARY, 1, 12, 0, 0); Week w = new Week(gc.getTime(), zone); assertEquals(53, w.getWeek()); assertEquals(new Year(2004), w.getYear()); } finally { Locale.setDefault(saved); } }
From source file:org.sakaiproject.calendar.impl.RecurrenceRuleBase.java
/** * Return a List of all RecurrenceInstance objects generated by this rule within the given time range, based on the * prototype first range, in time order.//from w ww . j av a 2s.co m * @param prototype The prototype first TimeRange. * @param range A time range to limit the generated ranges. * @param timeZone The time zone to use for displaying times. * %%% Note: this is currently not implemented, and always uses the "local" zone. * @return a List of RecurrenceInstance generated by this rule in this range. */ public List generateInstances(TimeRange prototype, TimeRange range, TimeZone timeZone) { // these calendars are used if local time zone and the time zone where the first event was created (timeZone) are different GregorianCalendar firstEventCalendarDate = null; GregorianCalendar nextFirstEventCalendarDate = null; // %%% Note: base the breakdonw on the "timeZone" parameter to support multiple timeZone displays -ggolden TimeBreakdown startBreakdown = prototype.firstTime().breakdownLocal(); GregorianCalendar startCalendarDate = TimeService.getCalendar(TimeService.getLocalTimeZone(), 0, 0, 0, 0, 0, 0, 0); startCalendarDate.set(startBreakdown.getYear(), startBreakdown.getMonth() - 1, startBreakdown.getDay(), startBreakdown.getHour(), startBreakdown.getMin(), startBreakdown.getSec()); // if local time zone and first event time zone are different // a new calendar is generated to calculate the re-occurring events // if not, the local time zone calendar is used boolean differentTimeZone = false; if (TimeService.getLocalTimeZone().getID().equals(timeZone.getID())) { differentTimeZone = false; } else { differentTimeZone = true; } if (differentTimeZone) { firstEventCalendarDate = TimeService.getCalendar(timeZone, 0, 0, 0, 0, 0, 0, 0); firstEventCalendarDate.setTimeInMillis(startCalendarDate.getTimeInMillis()); nextFirstEventCalendarDate = (GregorianCalendar) firstEventCalendarDate.clone(); } List rv = new Vector(); GregorianCalendar nextCalendarDate = (GregorianCalendar) startCalendarDate.clone(); int currentCount = 1; do { if (differentTimeZone) { // next time is calculated according to the first event time zone, not the local one nextCalendarDate.setTimeInMillis(nextFirstEventCalendarDate.getTimeInMillis()); } Time nextTime = TimeService.newTime(nextCalendarDate); // is this past count? if ((getCount() > 0) && (currentCount > getCount())) break; // is this past until? if ((getUntil() != null) && isAfter(nextTime, getUntil())) break; TimeRange nextTimeRange = TimeService.newTimeRange(nextTime.getTime(), prototype.duration()); // // Is this out of the range? // if (isOverlap(range, nextTimeRange)) { TimeRange eventTimeRange = null; // Single time cases require special handling. if (prototype.isSingleTime()) { eventTimeRange = TimeService.newTimeRange(nextTimeRange.firstTime()); } else { eventTimeRange = TimeService.newTimeRange(nextTimeRange.firstTime(), nextTimeRange.lastTime(), true, false); } // use this one rv.add(new RecurrenceInstance(eventTimeRange, currentCount)); } // if next starts after the range, stop generating else if (isAfter(nextTime, range.lastTime())) break; // advance interval years. if (differentTimeZone) { nextFirstEventCalendarDate = (GregorianCalendar) firstEventCalendarDate.clone(); nextFirstEventCalendarDate.add(getRecurrenceType(), getInterval() * currentCount); } else { nextCalendarDate = (GregorianCalendar) startCalendarDate.clone(); nextCalendarDate.add(getRecurrenceType(), getInterval() * currentCount); } currentCount++; } while (true); return rv; }
From source file:org.jfree.data.time.WeekTest.java
/** * A test for a problem in constructing a new Week instance. *//*from ww w . jav a 2s . c om*/ @Test public void testConstructor() { Locale savedLocale = Locale.getDefault(); TimeZone savedZone = TimeZone.getDefault(); Locale.setDefault(new Locale("da", "DK")); TimeZone.setDefault(TimeZone.getTimeZone("Europe/Copenhagen")); GregorianCalendar cal = (GregorianCalendar) Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault()); // first day of week is monday assertEquals(Calendar.MONDAY, cal.getFirstDayOfWeek()); cal.set(2007, Calendar.AUGUST, 26, 1, 0, 0); cal.set(Calendar.MILLISECOND, 0); Date t = cal.getTime(); Week w = new Week(t, TimeZone.getTimeZone("Europe/Copenhagen")); assertEquals(34, w.getWeek()); Locale.setDefault(Locale.US); TimeZone.setDefault(TimeZone.getTimeZone("US/Detroit")); cal = (GregorianCalendar) Calendar.getInstance(TimeZone.getDefault()); // first day of week is Sunday assertEquals(Calendar.SUNDAY, cal.getFirstDayOfWeek()); cal.set(2007, Calendar.AUGUST, 26, 1, 0, 0); cal.set(Calendar.MILLISECOND, 0); t = cal.getTime(); w = new Week(t, TimeZone.getTimeZone("Europe/Copenhagen")); assertEquals(35, w.getWeek()); w = new Week(t, TimeZone.getTimeZone("Europe/Copenhagen"), new Locale("da", "DK")); assertEquals(34, w.getWeek()); Locale.setDefault(savedLocale); TimeZone.setDefault(savedZone); }
From source file:com.marklogic.client.test.PojoFacadeTest.java
@Test public void testF_DateTime() { PojoRepository<TimeTest, String> times = Common.client.newPojoRepository(TimeTest.class, String.class); GregorianCalendar septFirst = new GregorianCalendar(TimeZone.getTimeZone("CET")); septFirst.set(2014, Calendar.SEPTEMBER, 1, 12, 0, 0); TimeTest timeTest1 = new TimeTest("1", septFirst); times.write(timeTest1);/*from w w w. j a v a2 s . c o m*/ TimeTest timeTest1FromDb = times.read("1"); assertEquals("Times should be equal", timeTest1.timeTest.getTime().getTime(), timeTest1FromDb.timeTest.getTime().getTime()); GregorianCalendar septFirstGMT = new GregorianCalendar(TimeZone.getTimeZone("GMT")); septFirstGMT.set(2014, Calendar.SEPTEMBER, 1, 12, 0, 0); TimeTest timeTest2 = new TimeTest("2", septFirstGMT); times.write(timeTest2); TimeTest timeTest2FromDb = times.read("2"); assertEquals("Times should be equal", timeTest2.timeTest, timeTest2FromDb.timeTest); }
From source file:kilim.http.HttpRequestParser.java
public static long parseDate(byte[] data, int pos, int len) { int p = 0;// w ww. j ava 2 s . c o m int pe = len; // int eof = pe; int cs; // int wkday = 0; int day = 0, month = 0, year = 0; int hh = 0, mm = 0, ss = 0; // line 1510 "HttpRequestParser.java" { cs = http_date_start; } // line 299 "HttpRequestParser.rl" // line 1517 "HttpRequestParser.java" { int _klen; int _trans = 0; int _acts; int _nacts; int _keys; int _goto_targ = 0; _goto: while (true) { switch (_goto_targ) { case 0: if (p == pe) { _goto_targ = 4; continue _goto; } if (cs == 0) { _goto_targ = 5; continue _goto; } case 1: _match: do { _keys = _http_date_key_offsets[cs]; _trans = _http_date_index_offsets[cs]; _klen = _http_date_single_lengths[cs]; if (_klen > 0) { int _lower = _keys; int _mid; int _upper = _keys + _klen - 1; while (true) { if (_upper < _lower) break; _mid = _lower + ((_upper - _lower) >> 1); if (data[p] < _http_date_trans_keys[_mid]) _upper = _mid - 1; else if (data[p] > _http_date_trans_keys[_mid]) _lower = _mid + 1; else { _trans += (_mid - _keys); break _match; } } _keys += _klen; _trans += _klen; } _klen = _http_date_range_lengths[cs]; if (_klen > 0) { int _lower = _keys; int _mid; int _upper = _keys + (_klen << 1) - 2; while (true) { if (_upper < _lower) break; _mid = _lower + (((_upper - _lower) >> 1) & ~1); if (data[p] < _http_date_trans_keys[_mid]) _upper = _mid - 2; else if (data[p] > _http_date_trans_keys[_mid + 1]) _lower = _mid + 2; else { _trans += ((_mid - _keys) >> 1); break _match; } } _trans += _klen; } } while (false); cs = _http_date_trans_targs[_trans]; if (_http_date_trans_actions[_trans] != 0) { _acts = _http_date_trans_actions[_trans]; _nacts = (int) _http_date_actions[_acts++]; while (_nacts-- > 0) { switch (_http_date_actions[_acts++]) { case 0: // line 254 "HttpRequestParser.rl" { day = day * 10 + (data[p] - 48); } break; case 1: // line 255 "HttpRequestParser.rl" { year = year * 10 + (data[p] - 48); } break; case 2: // line 256 "HttpRequestParser.rl" { hh = hh * 10 + (data[p] - 48); } break; case 3: // line 257 "HttpRequestParser.rl" { mm = mm * 10 + (data[p] - 48); } break; case 4: // line 258 "HttpRequestParser.rl" { ss = ss * 10 + (data[p] - 48); } break; case 5: // line 262 "HttpRequestParser.rl" { month = 0; } break; case 6: // line 263 "HttpRequestParser.rl" { month = 1; } break; case 7: // line 264 "HttpRequestParser.rl" { month = 2; } break; case 8: // line 265 "HttpRequestParser.rl" { month = 3; } break; case 9: // line 266 "HttpRequestParser.rl" { month = 4; } break; case 10: // line 267 "HttpRequestParser.rl" { month = 5; } break; case 11: // line 268 "HttpRequestParser.rl" { month = 6; } break; case 12: // line 269 "HttpRequestParser.rl" { month = 7; } break; case 13: // line 270 "HttpRequestParser.rl" { month = 8; } break; case 14: // line 271 "HttpRequestParser.rl" { month = 90; } break; case 15: // line 272 "HttpRequestParser.rl" { month = 10; } break; case 16: // line 273 "HttpRequestParser.rl" { month = 11; } break; // line 1664 "HttpRequestParser.java" } } } case 2: if (cs == 0) { _goto_targ = 5; continue _goto; } if (++p != pe) { _goto_targ = 1; continue _goto; } case 4: case 5: } break; } } // line 300 "HttpRequestParser.rl" if (year < 100) { year += 1900; } GregorianCalendar gc = new GregorianCalendar(); gc.set(year, month, day, hh, mm, ss); gc.setTimeZone(GMT); return gc.getTimeInMillis(); }
From source file:org.betaconceptframework.astroboa.console.jsf.browse.ContentObjectSearchByContentType.java
public String findContentObjectsByContentTypeAndPresent_UIAction() { // reset search criteria to begin a new search contentObjectCriteria = null;//from w w w. j a v a2s . c o m contentObjectCriteria = CmsCriteriaFactory.newContentObjectCriteria(); uiComponentBinding.resetContentObjectTableScrollerComponent(); contentObjectList.resetViewAndStateBeforeNewContentSearchResultsPresentation(); // We add the selected content type into search criteria HtmlTree contentObjectFolderTree = uiComponentBinding.getContentObjectFolderTreeRichFaces(); TreeNode selectedTreeNodeObject = contentObjectFolderTree.getTreeNode(); LazyLoadingContentObjectFolderTreeNodeRichFaces selectedNode; // There is possibly a bug in Rich Faces Tree Implementation. The first time a tree node is selected in the tree the selected tree node // that is returned has type <LazyLoadingContentObjectFolderTreeNodeRichFaces> as it should be. However any subsequent selected tree node // is returned as a <TreeNodeImpl> object which should not happen. // So we should check the returned type to decide how we will access the selected tree node. if (LazyLoadingContentObjectFolderTreeNodeRichFaces.class.isInstance(selectedTreeNodeObject)) { selectedNode = (LazyLoadingContentObjectFolderTreeNodeRichFaces) contentObjectFolderTree.getTreeNode(); } else if (TreeNodeImpl.class.isInstance(selectedTreeNodeObject)) { selectedNode = (LazyLoadingContentObjectFolderTreeNodeRichFaces) selectedTreeNodeObject.getData(); } else throw new RuntimeException("Cannot determine the class of the selected tree node"); contentObjectCriteria.addContentObjectTypeEqualsCriterion(selectedNode.getContentType()); contentObjectCriteria.doNotCacheResults(); // We should find and add the selected date into search criteria if a date folder has been selected String message = ""; if (!selectedNode.getType().equals("contentTypeFolder")) { String fullContentObjectFolderPath = selectedNode.getContentObjectFolder().getFullPath(); //the full path contains date information. Its format is the following: YYYY/M/D eg. 2006/5/2 String[] dateComponents = StringUtils.split(fullContentObjectFolderPath, "/"); // we split the path to the year, month and day components if (dateComponents == null || dateComponents.length == 0 || dateComponents.length > 3) { logger.error("Error while loading content objects. Invalid path for content object folder {}", fullContentObjectFolderPath); JSFUtilities.addMessage(null, "object.list.message.contentObjectRetrievalError", null, FacesMessage.SEVERITY_ERROR); return null; } GregorianCalendar fromDate = new GregorianCalendar(TimeZone.getDefault()); GregorianCalendar toDate = new GregorianCalendar(TimeZone.getDefault()); //Find out whether user has clicked a year, a month or a day if (dateComponents.length == 1) { //User has selected year. //Find all content objects created the selected year //from 01/01/selectedYear //to 31/12/selectedYear fromDate.set(Integer.valueOf(dateComponents[0]), 0, 1, 0, 0, 0); toDate.set(Integer.valueOf(dateComponents[0]), 11, 31, 23, 59, 59); message = DateUtils.format(fromDate, "dd/MM/yyyy") + " - " + DateUtils.format(toDate, "dd/MM/yyyy"); } else if (dateComponents.length == 2) { //User has selected month. //Find all content objects created the selected year //from 01/selectedMonth/selectedYear //to 31/selectedMonth/selectedYear //Fix Month information //In CmsBackEnd. month enumeration starts from 1 for January, 2 for February .etc //Where as in Java Calendar month enumeration is zero based. Thus we need a conversion String month = dateComponents[1]; int javaMonth = Integer.valueOf(month) - 1; fromDate.set(Integer.valueOf(dateComponents[0]), javaMonth, 1, 0, 0, 0); toDate.set(Integer.valueOf(dateComponents[0]), javaMonth, fromDate.getActualMaximum(Calendar.DAY_OF_MONTH), 23, 59, 59); message = DateUtils.format(fromDate, "dd/MM/yyyy") + " - " + DateUtils.format(toDate, "dd/MM/yyyy"); } else { //User has selected a day //from selectedDay at midnight //to selectedDay at 23:59:59.999 //Fix Month information //In CmsBackEnd. month enumeration starts from 1 for January, 2 for February .etc //Where as in Java Calendar month enumeration is zero based. Thus we need a conversion String month = dateComponents[1]; int javaMonth = Integer.valueOf(month) - 1; // we create a date range for the selected date (24 hours) fromDate.set(Integer.valueOf(dateComponents[0]), javaMonth, Integer.valueOf(dateComponents[2]), 0, 0, 0); toDate.set(Integer.valueOf(dateComponents[0]), javaMonth, Integer.valueOf(dateComponents[2]), 23, 59, 59); message = DateUtils.format(fromDate, "dd/MM/yyyy"); } //Above method is setting 0 to hour, minute and second but we also need to clear milliseconds fromDate.clear(Calendar.MILLISECOND); //System.out.println(DateUtils.format(fromDate, "dd/MM/yyyy HH:mm")); toDate.set(Calendar.MILLISECOND, 999); //System.out.println(DateUtils.format(toDate, "dd/MM/yyyy HH:mm")); contentObjectCriteria.addCriterion(CriterionFactory.between("profile.created", fromDate, toDate)); } contentObjectCriteria.setOffsetAndLimit(0, pageController.getRowsPerDataTablePage()); // set required ordering if (searchResultsFilterAndOrdering.getSelectedResultsOrder() != null) { contentObjectCriteria.addOrderProperty("profile.created", Order.valueOf(searchResultsFilterAndOrdering.getSelectedResultsOrder())); } else { contentObjectCriteria.addOrderProperty("profile.created", Order.descending); } // now we are ready to run the query try { long startTime = System.currentTimeMillis(); int resultSetSize = contentObjectStatefulSearchService.searchForContentWithPagedResults( contentObjectCriteria, true, JSFUtilities.getLocaleAsString(), pageController.getRowsPerDataTablePage()); long endTime = System.currentTimeMillis(); getLogger().debug("Find Objects by ContentObject Type and Date: " + (endTime - startTime) + "ms"); if (resultSetSize > 0) { String localisedNameOfBrowsedContentType = selectedNode.getLocalizedLabelOfContentType(); if ("".equals(message)) { contentObjectList.setContentObjectListHeaderMessage(JSFUtilities.getParameterisedStringI18n( "object.list.message.contentObjectListHeaderMessageForSearchByContentTypeWithoutDate", new String[] { localisedNameOfBrowsedContentType, String.valueOf(resultSetSize) })); } else { contentObjectList.setContentObjectListHeaderMessage(JSFUtilities.getParameterisedStringI18n( "object.list.message.contentObjectListHeaderMessageForSearchByContentType", new String[] { localisedNameOfBrowsedContentType, message, String.valueOf(resultSetSize) })); } contentObjectList.setLabelForFileGeneratedWhenExportingListToXml(localisedNameOfBrowsedContentType); } else JSFUtilities.addMessage(null, "object.list.message.noContentObjectsInThisContentObjectFolderInfo", null, FacesMessage.SEVERITY_INFO); } catch (Exception e) { logger.error("Error while loading content objects ", e); JSFUtilities.addMessage(null, "object.list.message.contentObjectRetrievalError", null, FacesMessage.SEVERITY_ERROR); } return null; }
From source file:org.apache.xmlgraphics.image.codec.png.PNGImageDecoder.java
private void parse_tIME_chunk(final PNGChunk chunk) { final int year = chunk.getInt2(0); final int month = chunk.getInt1(2) - 1; final int day = chunk.getInt1(3); final int hour = chunk.getInt1(4); final int minute = chunk.getInt1(5); final int second = chunk.getInt1(6); final TimeZone gmt = TimeZone.getTimeZone("GMT"); final GregorianCalendar cal = new GregorianCalendar(gmt); cal.set(year, month, day, hour, minute, second); final Date date = cal.getTime(); if (this.encodeParam != null) { this.encodeParam.setModificationTime(date); }/*from ww w . j a v a 2s. c o m*/ if (this.emitProperties) { this.properties.put("timestamp", date); } }