List of usage examples for java.util GregorianCalendar set
public void set(int field, int value)
From source file:com.mothsoft.alexis.engine.numeric.TopicActivityDataSetImporter.java
@Override public void importData() { if (this.transactionTemplate == null) { this.transactionTemplate = new TransactionTemplate(this.transactionManager); }/*from w w w . j a va 2 s . c o m*/ final List<Long> userIds = listUserIds(); final GregorianCalendar calendar = new GregorianCalendar(); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); int minute = calendar.get(Calendar.MINUTE); if (minute >= 45) { calendar.set(Calendar.MINUTE, 30); } else if (minute >= 30) { calendar.set(Calendar.MINUTE, 15); } else if (minute >= 15) { calendar.set(Calendar.MINUTE, 0); } else if (minute >= 0) { calendar.set(Calendar.MINUTE, 45); calendar.add(Calendar.HOUR_OF_DAY, -1); } final Date startDate = calendar.getTime(); calendar.add(Calendar.MINUTE, 15); calendar.add(Calendar.MILLISECOND, -1); final Date endDate = calendar.getTime(); for (final Long userId : userIds) { importTopicDataForUser(userId, startDate, endDate); } }
From source file:com.bt.heliniumstudentapp.ScheduleFragment.java
private static GregorianCalendar getDate() { GregorianCalendar date = new GregorianCalendar(HeliniumStudentApp.LOCALE); date.clear();/*from ww w . jav a 2 s. c o m*/ date.set(Calendar.YEAR, new GregorianCalendar(HeliniumStudentApp.LOCALE).get(Calendar.YEAR)); //FIXME BAD date.set(Calendar.WEEK_OF_YEAR, scheduleFocus); date.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); return date; }
From source file:com.icloud.framework.http.heritrix.ArchiveUtils.java
/** * Convert 17-digit date format timestamps (as found in crawl.log, for * example) into a GregorianCalendar object. + * Useful so you can convert * into milliseconds-since-epoch. Note: it is possible to compute * milliseconds-since-epoch + * using {@link #parse17DigitDate}.UTC(), but * that method is deprecated in favor of using Calendar.getTimeInMillis(). + * * <p/>I probably should have dug into all the utility methods in * DateFormat.java to parse the timestamp, but this was + * easier. If * someone wants to fix this to use those methods, please have at it! <p/> * Mike Schwartz, schwartz at CodeOnTheRoad dot com. * //from w w w. j a va 2s . c om * @param timestamp17String * @return Calendar set to <code>timestamp17String</code>. */ public static Calendar timestamp17ToCalendar(String timestamp17String) { GregorianCalendar calendar = new GregorianCalendar(); int year = Integer.parseInt(timestamp17String.substring(0, 4)); int dayOfMonth = Integer.parseInt(timestamp17String.substring(6, 8)); // Month is 0-based int month = Integer.parseInt(timestamp17String.substring(4, 6)) - 1; int hourOfDay = Integer.parseInt(timestamp17String.substring(8, 10)); int minute = Integer.parseInt(timestamp17String.substring(10, 12)); int second = Integer.parseInt(timestamp17String.substring(12, 14)); int milliseconds = Integer.parseInt(timestamp17String.substring(14, 17)); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); calendar.set(Calendar.HOUR_OF_DAY, hourOfDay); calendar.set(Calendar.MINUTE, minute); calendar.set(Calendar.SECOND, second); calendar.set(Calendar.MILLISECOND, milliseconds); return calendar; }
From source file:org.mariotaku.twidere.api.twitter.util.TwitterDateConverter.java
private Date parseTwitterDate(String string) { final String[] segs = StringUtils.split(string, ' '); if (segs.length != 6) { return null; }/*from w w w .j a va 2 s . c o m*/ final String[] timeSegs = StringUtils.split(segs[3], ':'); if (timeSegs.length != 3) { return null; } final GregorianCalendar calendar = new GregorianCalendar(TIME_ZONE, LOCALE); calendar.clear(); final int monthIdx = ArrayUtils.indexOf(MONTH_NAMES, segs[1]); if (monthIdx < 0) { return null; } calendar.set(Calendar.YEAR, Integer.parseInt(segs[5])); calendar.set(Calendar.MONTH, monthIdx); calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(segs[2])); calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(timeSegs[0])); calendar.set(Calendar.MINUTE, Integer.parseInt(timeSegs[1])); calendar.set(Calendar.SECOND, Integer.parseInt(timeSegs[2])); calendar.set(Calendar.ZONE_OFFSET, SimpleTimeZone.getTimeZone("GMT" + segs[4]).getRawOffset()); final Date date = calendar.getTime(); if (!WEEK_NAMES[calendar.get(Calendar.DAY_OF_WEEK) - 1].equals(segs[0])) { AbsLogger.error("Week mismatch " + string + " => " + date); return null; } return date; }
From source file:org.webical.test.web.component.DayViewPanelTest.java
public void testWithEvents() throws WebicalException { // Get the CalendarManager. MockCalendarManager mockCalendarManager = (MockCalendarManager) annotApplicationContextMock .getBean("calendarManager"); Calendar calendar1 = mockCalendarManager.getCalendarById("1"); // Add an EventManager for the test Events. MockEventManager mockEventManager = new MockEventManager(); annotApplicationContextMock.putBean("eventManager", mockEventManager); final GregorianCalendar currentDate = CalendarUtils.newTodayCalendar(getFirstDayOfWeek()); GregorianCalendar cal = CalendarUtils.duplicateCalendar(currentDate); GregorianCalendar refcal = CalendarUtils.duplicateCalendar(currentDate); refcal.set(GregorianCalendar.HOUR_OF_DAY, 12); refcal.set(GregorianCalendar.MINUTE, 0); refcal.set(GregorianCalendar.SECOND, 0); // Create list with events for the manager final List<Event> events = new ArrayList<Event>(); // Add a normal event Event event = new Event(); event.setUid("e1"); event.setCalendar(calendar1);/*from ww w . j a va 2 s . co m*/ event.setSummary("Normal Event Summary"); event.setLocation("Normal Event Location"); event.setDescription("Normal Event Description"); event.setDtStart(refcal.getTime()); event.setDtEnd(CalendarUtils.addHours(refcal.getTime(), 2)); log.debug( "Adding event: " + event.getDescription() + " -> " + event.getDtStart() + " - " + event.getDtEnd()); events.add(event); mockEventManager.storeEvent(event); // Add a recurring event, starting yesterday, ending tommorrow event = new Event(); event.setUid("e2"); event.setCalendar(calendar1); event.setSummary("Recurring Event Yesterday Summary"); event.setLocation("Recurring Event Location"); event.setDescription("Recurring Event Yesterday Description"); cal.setTime(refcal.getTime()); cal.add(GregorianCalendar.DAY_OF_MONTH, -1); event.setDtStart(cal.getTime()); cal.add(GregorianCalendar.HOUR_OF_DAY, 2); cal.add(GregorianCalendar.DAY_OF_MONTH, 2); event.setDtEnd(cal.getTime()); RecurrenceUtil.setRecurrenceRule(event, new Recurrence(0, 1, cal.getTime())); log.debug( "Adding event: " + event.getDescription() + " -> " + event.getDtStart() + " - " + event.getDtEnd()); events.add(event); mockEventManager.storeEvent(event); // Add a recurring event, starting last month, ending next month event = new Event(); event.setUid("e3"); event.setCalendar(calendar1); event.setSummary("Recurring Event Last Month Summary"); event.setLocation("Recurring Event Location"); event.setDescription("Recurring Event Last Month Description"); cal.setTime(refcal.getTime()); cal.add(GregorianCalendar.MONTH, -1); event.setDtStart(cal.getTime()); cal.add(GregorianCalendar.HOUR_OF_DAY, 2); cal.add(GregorianCalendar.MONTH, 2); event.setDtEnd(cal.getTime()); RecurrenceUtil.setRecurrenceRule(event, new Recurrence(0, 1, CalendarUtils.getEndOfDay(cal.getTime()))); log.debug( "Adding event: " + event.getDescription() + " -> " + event.getDtStart() + " - " + event.getDtEnd()); events.add(event); mockEventManager.storeEvent(event); // Add a (pseudo) all day event, starting today 00:00 hours, ending today 00:00 hours event = new Event(); event.setUid("e4"); event.setCalendar(calendar1); event.setSummary("Pseudo All Day Event"); event.setLocation("All Day Event Location"); event.setDescription("Starting yesterday midnight, ending today 00:00 hours"); cal.setTime(refcal.getTime()); cal.set(GregorianCalendar.HOUR_OF_DAY, 0); cal.set(GregorianCalendar.MINUTE, 0); cal.set(GregorianCalendar.SECOND, 0); event.setDtStart(cal.getTime()); cal.add(GregorianCalendar.DAY_OF_MONTH, 1); event.setDtEnd(cal.getTime()); log.debug( "Adding event: " + event.getDescription() + " -> " + event.getDtStart() + " - " + event.getDtEnd()); events.add(event); mockEventManager.storeEvent(event); // Create the test page with a DayViewPanel wicketTester.startPage(new ITestPageSource() { private static final long serialVersionUID = 1L; public Page getTestPage() { return new PanelTestPage(new DayViewPanel(PanelTestPage.PANEL_MARKUP_ID, 1, currentDate) { private static final long serialVersionUID = 1L; @Override public void onAction(IAction action) { /* NOTHING TO DO */ } }); } }); // Basic assertions wicketTester.assertRenderedPage(PanelTestPage.class); wicketTester.assertComponent(PanelTestPage.PANEL_MARKUP_ID, DayViewPanel.class); // Assert the heading label DateFormat dateFormat = new SimpleDateFormat("EEEE", getTestSession().getLocale()); wicketTester.assertLabel(PanelTestPage.PANEL_MARKUP_ID + ":dayLink", dateFormat.format(currentDate.getTime())); // Assert the number of events rendered String panelPath = PanelTestPage.PANEL_MARKUP_ID + ":eventItem"; wicketTester.assertListView(panelPath, events); }
From source file:com.advdb.footballclub.FootBallClub.java
private GregorianCalendar randomYear(int startYear, int endYear) { GregorianCalendar gc = new GregorianCalendar(); int year = randBetween(startYear, endYear); gc.set(GregorianCalendar.YEAR, year); int dayOfYear = randBetween(1, gc.getActualMaximum(GregorianCalendar.DAY_OF_YEAR)); gc.set(GregorianCalendar.DAY_OF_YEAR, dayOfYear); // System.out.println(gc.get(GregorianCalendar.YEAR) + "-" + (gc.get(GregorianCalendar.MONTH) + 1) + "-" + gc.get(GregorianCalendar.DAY_OF_MONTH)); return gc;//ww w .ja va2s .c om }
From source file:org.jbpm.formModeler.core.processing.formProcessing.Functions.java
public Map getValidDays(String sMonth, String sYear) { int month = Integer.decode(sMonth).intValue(); int year = Integer.decode(sYear).intValue(); GregorianCalendar gc = new GregorianCalendar(year, month, 1); Map days = new HashMap(); while (gc.get(GregorianCalendar.MONTH) == month) { Integer value = new Integer(gc.get(GregorianCalendar.DAY_OF_MONTH)); days.put(value, value.toString()); gc.set(GregorianCalendar.DAY_OF_MONTH, value.intValue() + 1); }/*from w w w .j a v a 2 s .c o m*/ return days; }
From source file:org.obm.caldav.obmsync.service.impl.CalendarService.java
private List<DavComponent> getAllLastUpdate(CalDavToken token, String compUrl, DavComponentType componant, CompFilter cf) throws Exception { Date start = null;//ww w . j a va2s .c o m Date end = null; if (cf.getTimeRange() != null && (cf.getTimeRange().getStart() != null || cf.getTimeRange().getEnd() != null)) { start = cf.getTimeRange().getStart(); end = cf.getTimeRange().getEnd(); if (start == null) { GregorianCalendar gc = new GregorianCalendar(); gc.set(Calendar.YEAR, gc.get(Calendar.YEAR) - 1); start = gc.getTime(); } if (end == null) { GregorianCalendar gc = new GregorianCalendar(); gc.set(Calendar.YEAR, gc.get(Calendar.YEAR) + 1); end = gc.getTime(); } } else { Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); cal.setTimeInMillis(0); start = cal.getTime(); end = null; } AbstractEventSyncClient obmClient = ObmSyncProviderFactory.getInstance().getClient(componant, token.getLoginAtDomain()); AccessToken obmToken = login(obmClient, token); List<EventTimeUpdate> items = new ArrayList<EventTimeUpdate>(0); try { items = obmClient.getEventTimeUpdateNotRefusedFromIntervalDate(obmToken, token.getCalendarName(), start, end); for (Iterator<EventTimeUpdate> it = items.iterator(); it.hasNext();) { EventTimeUpdate ev = it.next(); if (ev.getRecurrenceId() != null) { it.remove(); } } } catch (Exception e) { throw new Exception(); } finally { logout(obmClient, obmToken); } return EventConverter.convert(items, compUrl, componant); }
From source file:com.projity.options.CalendarOption.java
public long makeValidEnd(long end, boolean force) { end = DateTime.minuteFloor(end);//from ww w .ja va 2 s. c om GregorianCalendar cal = DateTime.calendarInstance(); cal.setTimeInMillis(end); if (force || cal.get(GregorianCalendar.HOUR_OF_DAY) == 0 && cal.get(GregorianCalendar.MINUTE) == 0) { cal.set(GregorianCalendar.HOUR_OF_DAY, getDefaultEndTime().get(GregorianCalendar.HOUR_OF_DAY)); cal.set(GregorianCalendar.MINUTE, getDefaultEndTime().get(GregorianCalendar.MINUTE)); } return cal.getTimeInMillis(); }
From source file:com.quartz.AmazonQuartzJob.java
public void execute(JobExecutionContext context) throws JobExecutionException { String error = "No error"; SimpleDateFormat out = new SimpleDateFormat("hh:mm a"); System.out.println(":::>>>Amazon Job Time Check @ " + out.format(new Date())); settingsHM = TextFileReadWrite.readSettings(file); String onoff = settingsHM.get("onoff"), emails = settingsHM.get("emails"), lastUpdate = settingsHM.get("lastUpdate"); ArrayList<String> time = new ArrayList(Arrays.asList(settingsHM.get("time").split(";"))); if (emails == null) { emails = ";"; }// ww w. j a v a2s. c om Date lastDate; try { lastDate = out1.parse(lastUpdate); } catch (ParseException ex) { GregorianCalendar now = new GregorianCalendar(); now.set(Calendar.DAY_OF_YEAR, -1); lastDate = now.getTime(); } String[] emailArr = emails.replace(";;", ";").replace(";", " ").trim().split(" "); if (onoff.equalsIgnoreCase("checked")) { for (String e : time) { Date dScheduled, dNow; try { dScheduled = out.parse(e); dNow = out.parse(out.format(new Date())); if (dScheduled.getTime() == dNow.getTime()) { System.out.println("\t---> Amazon task launch"); XMLOrderConfirmationFeedBuilder.generateShipConfirmXML(); try { this.submitFeed(); } catch (IOException ex) { System.out.println("Error occured in submitFeed method"); error += "Cannot submit feed."; } try { if (emails != null && emails.length() > 0) { for (String recipient : emailArr) { InternetAddress.parse(recipient); if (recipient.indexOf("@") > 0 && recipient.indexOf(".") > 0) { String subject = "Auto notification from AMZ order update application server"; String msg = "Scheduled Amazon orders update executed.\nError/s: " + error + "\n\n Update contents:\n\n" + XML.toJSONObject(TextFileReadWrite .readFile(new File("AMZ_Orders_Tracking_Feed.xml"))[0]) .toString(3); Emailer.Send(AKC_Creds.ANH_EMAIL, AKC_Creds.ANH_EMAIL_PWD, recipient, subject, msg); } } } System.out.println("===[email notifications send]==="); writeUpdateTimestamp(); } catch (MessagingException ex) { System.out.println(ex.getMessage()); } } else { //System.out.println("\txxx> AMZ task time not match | Scheduled: " + out.format(dScheduled) + " Now: " + out.format(dNow)); } } catch (ParseException ex) { //System.out.println(ex.getMessage()); error += " Cannot create XML feed."; } } } }