List of usage examples for java.util GregorianCalendar set
public void set(int field, int value)
From source file:TimePeriod.java
/** * Setzt den bis-Wert auf einen der Standard-Typen * /*from w ww .ja v a 2 s . co m*/ * @param neuertyp */ public void setToTyp(int neuertyp) { this.to_typ = neuertyp; if (from_typ != to_typ) typ = -1; else typ = neuertyp; switch (neuertyp) { case TODAY: to = new GregorianCalendar(); set2359(to); break; case YESTERDAY: to = new GregorianCalendar(); set2359(to); to.setTimeInMillis(to.getTimeInMillis() - ONE_DAY); break; case THIS_WEEK: to = new GregorianCalendar(); int day_of_week = to.get(Calendar.DAY_OF_WEEK); // unsere Woche beginnt am Montag. Montag hat den Wert 2 int day_offset_von; // wenn es sonntag ist, wird die zurck liegende woche betrachtet if (day_of_week == 1) { day_offset_von = -6; } else { day_offset_von = 2 - day_of_week; } // bis ist logischerweise 6-Tage nach von int day_offset_bis = day_offset_von + 6; set2359(to); to.setTimeInMillis(to.getTimeInMillis() + ONE_DAY * day_offset_bis); break; case LAST_WEEK: // wie diese woche, nur 7 tage weiter zurck to = new GregorianCalendar(); int day_of_week2 = to.get(Calendar.DAY_OF_WEEK); // unsere Woche beginnt am Montag. Montag hat den Wert 2 int day_offset_von2; // wenn es sonntag ist, wird die zurck liegende woche betrachtet if (day_of_week2 == 1) { day_offset_von2 = -13; } else { day_offset_von2 = -5 - day_of_week2; } // bis ist logischerweise 6-Tage nach von int day_offset_bis2 = day_offset_von2 + 6; set2359(to); to.setTimeInMillis(to.getTimeInMillis() + ONE_DAY * day_offset_bis2); break; case THIS_MONTH: GregorianCalendar temp = new GregorianCalendar(); setMidnight(temp); temp.set(Calendar.DAY_OF_MONTH, 1); to = new GregorianCalendar(); set2359(to); // wann der letzte tag im monat ist ist unklar, also solange weiter // gehen, // bis der neue monat anfngt, dann einen tag zurck while (to.get(Calendar.MONTH) == temp.get(Calendar.MONTH)) to.setTimeInMillis(to.getTimeInMillis() + ONE_DAY); // Jetzt wieder einen tag zurck to.setTimeInMillis(to.getTimeInMillis() - ONE_DAY); break; case LAST_MONTH: GregorianCalendar temp2 = new GregorianCalendar(); setMidnight(temp2); temp2.set(Calendar.DAY_OF_MONTH, 1); // der erste tag des letzten Monats ist vielleicht nicht mehr in // diesem Jahr, also // rckwrts laufen, bis wieder ein erster Tag gefunden wird temp2.setTimeInMillis(temp2.getTimeInMillis() - ONE_DAY); to = new GregorianCalendar(); to.setTimeInMillis(temp2.getTimeInMillis()); set2359(to); break; case THIS_JEAR: to = new GregorianCalendar(); set2359(to); to.set(Calendar.MONTH, 11); to.set(Calendar.DAY_OF_MONTH, 31); break; case LAST_JEAR: to = new GregorianCalendar(); int jahr = to.get(Calendar.YEAR); jahr--; set2359(to); to.set(Calendar.MONTH, 11); to.set(Calendar.DAY_OF_MONTH, 31); to.set(Calendar.YEAR, jahr); break; case EVER: to = new GregorianCalendar(); int jahr2 = to.get(Calendar.YEAR); set2359(to); to.set(Calendar.MONTH, 11); to.set(Calendar.DAY_OF_MONTH, 31); to.set(Calendar.YEAR, jahr2); break; } // Von darf nicht nach bis liegen, ist bis schon initialisiert, so muss // es angepasst werden if (from != null) if (to.before(from)) { from.setTimeInMillis(to.getTimeInMillis()); setMidnight(from); from_typ = to_typ; } }
From source file:cs.gui.stats.PerformanceStats.java
private void updateCurrentMaximumRange(int hour, int day, int month, int year) { // set the initial date to 01/01/2010 GregorianCalendar calendar = new GregorianCalendar(); calendar.set(GregorianCalendar.HOUR_OF_DAY, hour); calendar.set(GregorianCalendar.DAY_OF_MONTH, day); calendar.set(GregorianCalendar.MONTH, month - 1); calendar.set(GregorianCalendar.YEAR, year); Date currentDate = calendar.getTime(); if (scope1 == 0) { dateAxis1.setMaximumDate(currentDate); }// ww w .j a v a 2 s .c o m if (scope2 == 0) { dateAxis2.setMaximumDate(currentDate); } if (scope3 == 0) { dateAxis3.setMaximumDate(currentDate); } if (scope4 == 0) { dateAxis4.setMaximumDate(currentDate); } if (scope5 == 0) { dateAxis5.setMaximumDate(currentDate); } }
From source file:cs.gui.stats.PerformanceStats.java
public PerformanceStats(ModelInterface modelInterfaceRef, StatsManager statsManagerRer) { super(new BorderLayout()); this.modelInterface = modelInterfaceRef; this.statsManager = statsManagerRer; datasets = new TimeSeriesCollection[SUBPLOT_COUNT]; // set the initial date according to the one specified in SystemClock object GregorianCalendar calendar = new GregorianCalendar(); calendar.set(GregorianCalendar.HOUR_OF_DAY, modelInterface.getSimulationClock().getStartTime().get(Calendar.HOUR_OF_DAY)); calendar.set(GregorianCalendar.DAY_OF_MONTH, modelInterface.getSimulationClock().getStartTime().get(Calendar.DAY_OF_MONTH)); calendar.set(GregorianCalendar.MONTH, modelInterface.getSimulationClock().getStartTime().get(Calendar.MONTH)); calendar.set(GregorianCalendar.YEAR, modelInterface.getSimulationClock().getStartTime().get(Calendar.YEAR)); //setup the initial date range GregorianCalendar calendarForInitialDateRange = new GregorianCalendar(); calendarForInitialDateRange.set(GregorianCalendar.HOUR_OF_DAY, modelInterface.getSimulationClock().getStartTime().get(Calendar.HOUR_OF_DAY)); calendarForInitialDateRange.set(GregorianCalendar.DAY_OF_MONTH, modelInterface.getSimulationClock().getStartTime().get(Calendar.DAY_OF_MONTH)); calendarForInitialDateRange.set(GregorianCalendar.MONTH, modelInterface.getSimulationClock().getStartTime().get(Calendar.MONTH)); calendarForInitialDateRange.set(GregorianCalendar.YEAR, modelInterface.getSimulationClock().getStartTime().get(Calendar.YEAR)); initialDateRange = new DateRange(calendarForInitialDateRange.getTime(), calendar.getTime()); initialDateRange1 = new DateRange(calendarForInitialDateRange.getTime(), calendar.getTime()); initialDateRange2 = new DateRange(calendarForInitialDateRange.getTime(), calendar.getTime()); initialDateRange3 = new DateRange(calendarForInitialDateRange.getTime(), calendar.getTime()); initialDateRange4 = new DateRange(calendarForInitialDateRange.getTime(), calendar.getTime()); initialDateRange5 = new DateRange(calendarForInitialDateRange.getTime(), calendar.getTime()); JPanel tabbedPanel = createChartTab(); add(tabbedPanel, "North"); }
From source file:org.dmfs.tasks.notification.NotificationUpdaterService.java
@TargetApi(Build.VERSION_CODES.KITKAT) private void updateNextDayAlarm() { Intent intent = new Intent(this, NotificationUpdaterService.class); intent.setAction(ACTION_NEXT_DAY);/* w w w .j a v a 2 s . c o m*/ mDateChangePendingIntent = PendingIntent.getService(this, 0, intent, 0); // set alarm to update the next day GregorianCalendar tomorrow = new GregorianCalendar(); tomorrow.add(Calendar.DAY_OF_YEAR, 1); tomorrow.set(Calendar.HOUR_OF_DAY, 0); tomorrow.set(Calendar.MINUTE, 0); tomorrow.set(Calendar.SECOND, 0); tomorrow.set(Calendar.MILLISECOND, 0); AlarmManager alarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) { alarmManager.setWindow(AlarmManager.RTC, tomorrow.getTimeInMillis(), 1000, mDateChangePendingIntent); } else { alarmManager.set(AlarmManager.RTC, tomorrow.getTimeInMillis(), mDateChangePendingIntent); } }
From source file:ca.uhn.hl7v2.model.primitive.tests.CommonTSTest.java
@Test public void testToHl7TMFormat() throws DataTypeException { GregorianCalendar cal = new GregorianCalendar(); cal.clear();/*from w w w. j a v a2 s. c o m*/ cal.setLenient(false); cal.set(Calendar.HOUR_OF_DAY, 20); cal.set(Calendar.MINUTE, 6); cal.set(Calendar.SECOND, 24); cal.set(Calendar.MILLISECOND, 528); String convertedDate = CommonTM.toHl7TMFormat(cal); assertEquals("Should get a HL7 formatted date back", "200624.528-0500", convertedDate); }
From source file:cs.stats.gui.StatsCharts.java
private void updateCurrentMaximumRange(int hour, int day, int month, int year) { // set the initial date to 01/01/2010 GregorianCalendar calendar = new GregorianCalendar(); calendar.set(GregorianCalendar.HOUR_OF_DAY, hour); calendar.set(GregorianCalendar.DAY_OF_MONTH, day); calendar.set(GregorianCalendar.MONTH, month); calendar.set(GregorianCalendar.YEAR, year); Date currentDate = calendar.getTime(); if (scope1 == 0) { dateAxis1.setMaximumDate(currentDate); }//from w w w.j av a2 s.c o m if (scope2 == 0) { dateAxis2.setMaximumDate(currentDate); } if (scope3 == 0) { dateAxis3.setMaximumDate(currentDate); } if (scope4 == 0) { dateAxis4.setMaximumDate(currentDate); } if (scope5 == 0) { dateAxis5.setMaximumDate(currentDate); } }
From source file:cs.stats.gui.StatsCharts.java
public StatsCharts(double tresholdTRT) { super(new BorderLayout()); this.tresholdTRT = tresholdTRT; datasets = new TimeSeriesCollection[SUBPLOT_COUNT]; // set the initial date according to the one specified in SystemClock object GregorianCalendar calendar = new GregorianCalendar(); calendar.set(GregorianCalendar.HOUR, 8); calendar.set(GregorianCalendar.DAY_OF_MONTH, 1); calendar.set(GregorianCalendar.MONTH, 2); calendar.set(GregorianCalendar.YEAR, 2010); //setup the initial date range GregorianCalendar calendarForInitialDateRange = new GregorianCalendar(); calendarForInitialDateRange.set(GregorianCalendar.HOUR, 8); calendarForInitialDateRange.set(GregorianCalendar.DAY_OF_MONTH, 1); calendarForInitialDateRange.set(GregorianCalendar.MONTH, 2); calendarForInitialDateRange.set(GregorianCalendar.YEAR, 2010); initialDateRange = new DateRange(calendarForInitialDateRange.getTime(), calendar.getTime()); initialDateRange1 = new DateRange(calendarForInitialDateRange.getTime(), calendar.getTime()); initialDateRange2 = new DateRange(calendarForInitialDateRange.getTime(), calendar.getTime()); initialDateRange3 = new DateRange(calendarForInitialDateRange.getTime(), calendar.getTime()); initialDateRange4 = new DateRange(calendarForInitialDateRange.getTime(), calendar.getTime()); initialDateRange5 = new DateRange(calendarForInitialDateRange.getTime(), calendar.getTime()); JPanel tabbedPanel = createChartTab(); add(tabbedPanel, "North"); }
From source file:com.zimbra.qa.unittest.TestCalDav.java
public static ParsedDateTime parsedDateTime(int year, int month, int day, int hour, int min, ICalTimeZone icalTimeZone) {/* w w w . j a v a 2 s . co m*/ GregorianCalendar date = new GregorianCalendar(); date.set(java.util.Calendar.YEAR, year); date.set(java.util.Calendar.MONTH, month); date.set(java.util.Calendar.DAY_OF_MONTH, month); date.set(java.util.Calendar.HOUR_OF_DAY, hour); date.set(java.util.Calendar.MINUTE, min); date.set(java.util.Calendar.SECOND, 0); return ParsedDateTime.fromUTCTime(date.getTimeInMillis(), icalTimeZone); }
From source file:org.alfresco.mobile.android.application.fragments.workflow.CreateTaskFragment.java
@Override public void onDatePicked(String dateId, GregorianCalendar gregorianCalendar) { if (getSession() instanceof RepositorySessionImpl && ((RepositorySessionImpl) getSession()).hasPublicAPI()) { gregorianCalendar.set(Calendar.HOUR_OF_DAY, 00); gregorianCalendar.set(Calendar.MINUTE, 00); gregorianCalendar.set(Calendar.SECOND, 00); gregorianCalendar.set(Calendar.MILLISECOND, 000); } else {/*from w w w . j ava2 s .c o m*/ gregorianCalendar.set(Calendar.HOUR_OF_DAY, 23); gregorianCalendar.set(Calendar.MINUTE, 59); gregorianCalendar.set(Calendar.SECOND, 59); gregorianCalendar.set(Calendar.MILLISECOND, 999); } dueAt = gregorianCalendar; Button dueOn = (Button) viewById(R.id.process_due_on); dueOn.setText(DateFormat.getDateFormat(getActivity()).format(dueAt.getTime())); }
From source file:ucar.unidata.data.storm.Diamond7StormDataSource.java
/** * _more_/* w ww . j av a 2 s .co m*/ * * @param year _more_ * @param month _more_ * @param day _more_ * @param hour _more_ * * @return _more_ * * @throws Exception _more_ */ private DateTime getDateTime(int year, int month, int day, int hour) throws Exception { GregorianCalendar convertCal = new GregorianCalendar(DateUtil.TIMEZONE_GMT); convertCal.clear(); convertCal.set(Calendar.YEAR, year); //The MONTH is 0 based. The incoming month is 1 based convertCal.set(Calendar.MONTH, month - 1); convertCal.set(Calendar.DAY_OF_MONTH, day); convertCal.set(Calendar.HOUR_OF_DAY, hour); return new DateTime(convertCal.getTime()); }