List of usage examples for java.util GregorianCalendar getTimeInMillis
public long getTimeInMillis()
From source file:re.serialout.MainScreen.java
public void debugButton(View view) { //This button makes the debug buttons appear and dissapear if you tap the screen 7 times quickly. timesPressed++;//from ww w. j a v a 2 s. c o m GregorianCalendar cal = new GregorianCalendar(); if (timesPressed == 1) { initTime = cal.getTimeInMillis(); } else if (cal.getTimeInMillis() - initTime > 3000) { timesPressed = 1; initTime = cal.getTimeInMillis(); } else if (!debugMode && timesPressed > 6 && cal.getTimeInMillis() - initTime < 3000) { //ACTIVATE DEBUG MODE debugMode = true; Button testButton = (Button) findViewById(R.id.testButton); testButton.setVisibility(View.VISIBLE); Button stressTest = (Button) findViewById(R.id.stressTest); stressTest.setVisibility(View.VISIBLE); Button record = (Button) findViewById(R.id.recordButton); record.setVisibility(View.VISIBLE); TextView freqText = (TextView) findViewById(R.id.freqtext); freqText.setVisibility(View.VISIBLE); findViewById(R.id.potStatButton).setVisibility(View.VISIBLE); SeekBar freqSeek = (SeekBar) findViewById(R.id.freqSeekBar); freqSeek.setVisibility(View.VISIBLE); findViewById(R.id.probeButton).setVisibility(View.VISIBLE); findViewById(R.id.lanuchPhButton).setVisibility(View.VISIBLE); findViewById(R.id.lanuchTimeSeries).setVisibility(View.VISIBLE); timesPressed = 0; } else if (debugMode && timesPressed > 6 && cal.getTimeInMillis() - initTime < 3000) { debugMode = false; Button stressTest = (Button) findViewById(R.id.stressTest); stressTest.setVisibility(View.GONE); Button testButton = (Button) findViewById(R.id.testButton); testButton.setVisibility(View.GONE); Button record = (Button) findViewById(R.id.recordButton); record.setVisibility(View.GONE); TextView freqText = (TextView) findViewById(R.id.freqtext); freqText.setVisibility(View.GONE); SeekBar freqSeek = (SeekBar) findViewById(R.id.freqSeekBar); freqSeek.setVisibility(View.GONE); findViewById(R.id.potStatButton).setVisibility(View.GONE); findViewById(R.id.probeButton).setVisibility(View.GONE); findViewById(R.id.lanuchPhButton).setVisibility(View.GONE); findViewById(R.id.lanuchTimeSeries).setVisibility(View.GONE); timesPressed = 0; } }
From source file:kilim.http.HttpRequestParser.java
public static long parseDate(byte[] data, int pos, int len) { int p = 0;//w w w.j a va 2s . 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:voldemort.scheduled.DataCleanupJobTest.java
public void testCleanupStartTime() { // Make sure the default is always the next day. GregorianCalendar cal = new GregorianCalendar(); assertEquals("Default is not tomorrow", Utils.getDayOfTheWeekFromNow(1), (cal.get(Calendar.DAY_OF_WEEK) + 1) % 7); // When starting the server any day in the week from SUN to FRI and // targeting a saturday, should always start on the next saturday GregorianCalendar expectedStart = TestUtils.getCalendar(2012, Calendar.SEPTEMBER, 29, 0, 0, 0); Random rand = new Random(); for (int day = Calendar.SUNDAY; day <= Calendar.FRIDAY; day++) { GregorianCalendar serverStartTime = TestUtils.getCalendar(2012, Calendar.SEPTEMBER, 22 + day, rand.nextInt(24), rand.nextInt(60), rand.nextInt(60)); GregorianCalendar computedStart = Utils.getCalendarForNextRun(serverStartTime, Calendar.SATURDAY, 0); assertEquals(/*from ww w. jav a 2 s. c o m*/ "Expected :" + expectedStart.getTimeInMillis() + " Computed: " + computedStart.getTimeInMillis(), expectedStart.getTimeInMillis(), computedStart.getTimeInMillis()); } // Targeting saturday, 00:00 and starting on a friday 23:59:59 should // start the next saturday GregorianCalendar serverStartTime = TestUtils.getCalendar(2012, Calendar.SEPTEMBER, 28, 23, 59, 59); GregorianCalendar computedStart = Utils.getCalendarForNextRun(serverStartTime, Calendar.SATURDAY, 0); assertEquals( "Expected :" + expectedStart.getTimeInMillis() + " Computed: " + computedStart.getTimeInMillis(), expectedStart.getTimeInMillis(), computedStart.getTimeInMillis()); // If we start past the start hour on the target day, it should start // the next week serverStartTime = TestUtils.getCalendar(2012, Calendar.SEPTEMBER, 29, 1, 0, 1); computedStart = Utils.getCalendarForNextRun(serverStartTime, Calendar.SATURDAY, 0); assertEquals(Calendar.SATURDAY, computedStart.get(Calendar.DAY_OF_WEEK)); assertEquals(serverStartTime.get(Calendar.DAY_OF_YEAR) + 7, computedStart.get(Calendar.DAY_OF_YEAR)); }
From source file:cz.zcu.kiv.eegdatabase.logic.controller.group.BookingRoomController.java
@Override public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object comm, BindException bindException) throws Exception { try {/*from w w w . j a v a 2 s.c om*/ BookRoomCommand command = (BookRoomCommand) comm; status = messageSource.getMessage("bookRoom.controllerMessages.status.fail", null, RequestContextUtils.getLocale(request)); comment = messageSource.getMessage("bookRoom.controllerMessages.comment.error.unknown", null, RequestContextUtils.getLocale(request)); Person user = personDao.getLoggedPerson(); int group = command.getSelectedGroup(); int repType = command.getRepType(); int repCount = command.getRepCount(); String startStr = BookingRoomUtils.getHoursAndMinutes(command.getStartTimeCal()); String endStr = BookingRoomUtils.getHoursAndMinutes(command.getEndTimeCal()); Reservation res = new Reservation(); Timestamp createTime = new Timestamp(new GregorianCalendar().getTimeInMillis()); res.setCreationTime(createTime); res.setStartTime(command.getStartTimeTimestamp()); res.setEndTime(command.getEndTimeTimestamp()); res.setPerson(user); //searching for ResearchGroup ResearchGroup grp = getResearchGroup(group); res.setResearchGroup(grp); log.debug("Reservation has been created: " + ((res == null) ? "false" : "true")); reservationDao.create(res); if (repCount > 0) { comment = messageSource.getMessage("bookRoom.controllerMessages.comment.booked.multiple.part1", null, RequestContextUtils.getLocale(request)); comment += command.getDate() + ", from " + startStr + " to " + endStr + "<br>\n"; GregorianCalendar nextS = command.getStartTimeCal(); GregorianCalendar nextE = command.getEndTimeCal(); for (int i = 0; i < repCount; i++) { //shift of dates int add = BookingRoomUtils.getWeeksAddCount(repType, i); nextS.add(Calendar.WEEK_OF_YEAR, add); nextE.add(Calendar.WEEK_OF_YEAR, add); Reservation newReservation = new Reservation(); newReservation.setCreationTime(createTime); newReservation.setStartTime(new Timestamp(nextS.getTimeInMillis())); newReservation.setEndTime(new Timestamp(nextE.getTimeInMillis())); newReservation.setPerson(user); newReservation.setResearchGroup(grp); reservationDao.create(newReservation); comment += BookingRoomUtils.getDate(nextS) + ", from " + BookingRoomUtils.getHoursAndMinutes(nextS) + " to " + BookingRoomUtils.getHoursAndMinutes(nextE) + "<br>\n"; } comment += String.format( messageSource.getMessage("bookRoom.controllerMessages.comment.booked.multiple.part2", null, RequestContextUtils.getLocale(request)), repCount + 1);//+1 because we need count "original" reservation! } else { comment = String .format(messageSource.getMessage("bookRoom.controllerMessages.comment.booked.single", null, RequestContextUtils.getLocale(request)), command.getDate(), startStr, endStr); } status = messageSource.getMessage("bookRoom.controllerMessages.status.ok", null, RequestContextUtils.getLocale(request)); } catch (Exception e) { log.error("Exception: " + e.getMessage() + "\n" + e.getStackTrace()[0].getFileName() + " at line " + e.getStackTrace()[0].getLineNumber(), e); status = messageSource.getMessage("bookRoom.controllerMessages.status.fail", null, RequestContextUtils.getLocale(request)); comment = messageSource.getMessage("bookRoom.controllerMessages.comment.error.exception", null, RequestContextUtils.getLocale(request)) + " " + e.getMessage(); } log.debug("Returning MAV" + " with status=" + status + "&comment=" + comment); ModelAndView mav = new ModelAndView(getSuccessView()/* + "?status=" + status + "&comment=" + comment*/); return mav; }
From source file:carsharing.starter.automotive.iot.ibm.com.mobilestarterapp.AnalyzeMyDriving.java
public void reserveCar() { // reserve my device as a car final String url = API.reservation; final GregorianCalendar temp = new GregorianCalendar(); final long pickupTime = temp.getTimeInMillis() / 1000; final long dropoffTime = (temp.getTimeInMillis() / 1000) + 3600; final Uri.Builder builder = new Uri.Builder().appendQueryParameter("carId", deviceID) .appendQueryParameter("pickupTime", pickupTime + "") .appendQueryParameter("dropOffTime", dropoffTime + ""); final String query = builder.build().getEncodedQuery(); try {/*from w w w . jav a2 s . co m*/ final API.doRequest task = new API.doRequest(new API.doRequest.TaskListener() { @Override public void postExecute(JSONArray result) throws JSONException { final JSONObject serverResponse = result.getJSONObject(result.length() - 1); final int statusCode = serverResponse.getInt("statusCode"); result.remove(result.length() - 1); switch (statusCode) { case 200: // start driving startedDriving = true; reservationId[0] = result.getJSONObject(0).getString("reservationId"); Reservations.userReserved = true; Log.i("Reservation", "Made=" + result.toString()); getAccurateLocation(mMap); break; case 409: ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle("Car already taken."); Log.i("Reservation", "Already Exists=" + result.toString()); useExistingReservation(); break; case 404: ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle("Car not available."); Log.i("Reservation", "Not Made" + result.toString()); break; default: ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle("Something went wrong."); Log.i("Reservation", "Error" + result.toString()); } } }); alreadyReserved = true; task.execute(url, "POST", query).get(); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } }
From source file:fhtw.lvplan.LV_PlanActivity.java
@Override public void onCreate(Bundle savedInstanceState) { /*View title = getWindow().findViewById(android.R.id.title); View titleBar = (View) title.getParent(); titleBar.setBackgroundColor(Color.parseColor("#0087c7"));*/ try {/*from w w w . j av a 2 s . c om*/ super.onCreate(savedInstanceState); setContentView(R.layout.main); epView = (ExpandableListView) findViewById(R.id.expandableListView1); Settings set = SettingsManager.getInstance(this.getBaseContext()).getSettingsInstance(); //Read Credentials if existing, if not --> Open Credentials Dialog to create settings if (set == null) { CredDialog.showChangelog = true; startCredDialog(); } else { //Check if Calendar already downloaded... //Downloaded is true per default if (DOWNLOADED) { if (set.getLastUpdate() != null) { GregorianCalendar now = new GregorianCalendar(); //Validate Update Interval settings. switch (set.getUpdateInterval()) { case STARTUP: DownloadFromUrl(); break; case DAILY: long delta = now.getTimeInMillis() - set.getLastUpdate().getTimeInMillis(); if (delta >= 24 * 60 * 60 * 100) { DownloadFromUrl(); } else if (delta > 0) { if (now.get(Calendar.DAY_OF_YEAR) > set.getLastUpdate().get(Calendar.DAY_OF_YEAR)) { DownloadFromUrl(); } } break; case MONTHLY: if (now.get(Calendar.YEAR) > set.getLastUpdate().get(Calendar.YEAR)) { DownloadFromUrl(); } else if (now.get(Calendar.MONTH) > set.getLastUpdate().get(Calendar.MONTH)) { DownloadFromUrl(); } break; default: // MANUAL do nothing break; } } List<LvPlanEntries> entries = CalendarReader.getLvPlanEntries(); if (entries == null) { ReadCalender(); //Reread if there aren't any } else { this.UpateCalendarUI(entries); } } else { DownloadFromUrl(); } //Verify if newer version installed if (Changelog.verifyVersionChanged(this)) { Changelog.viewChangelog(this); } } //Init List mAdapter = new MyExpandableListAdapter(this, groups, children); epView.setAdapter(mAdapter); } catch (Exception ex) { Log.d("OnCreate", "Exception: ", ex); } }
From source file:TimePeriod.java
/** * Gibt zurck, wie oft der bergebene Wochentag im Zeitraum vorkommt. * // w w w.j a v a2s.c om * @param wochentag * Sonntag = 1 * @return */ public int getNumberOfWeekdays(int wochentag) { int ergebnis = 0; GregorianCalendar temp = new GregorianCalendar(); temp.setTime(from.getTime()); // Schleife ber alle Tage int aktuellerTag; while (temp.before(to)) { aktuellerTag = temp.get(Calendar.DAY_OF_WEEK); if (aktuellerTag == wochentag) ergebnis++; temp.setTimeInMillis(temp.getTimeInMillis() + ONE_DAY); } return ergebnis; }
From source file:com.projity.options.CalendarOption.java
public long makeValidStart(long start, boolean force) { start = DateTime.minuteFloor(start); GregorianCalendar cal = DateTime.calendarInstance(); cal.setTimeInMillis(start);/* ww w . j a v a2s. c om*/ int year = cal.get(GregorianCalendar.YEAR); int dayOfYear = cal.get(GregorianCalendar.DAY_OF_YEAR); if (force || cal.get(GregorianCalendar.HOUR_OF_DAY) == 0 && cal.get(GregorianCalendar.MINUTE) == 0) { cal.set(GregorianCalendar.HOUR_OF_DAY, getDefaultStartTime().get(GregorianCalendar.HOUR_OF_DAY)); cal.set(GregorianCalendar.MINUTE, getDefaultStartTime().get(GregorianCalendar.MINUTE)); cal.set(GregorianCalendar.YEAR, year); cal.set(GregorianCalendar.DAY_OF_YEAR, dayOfYear); } return cal.getTimeInMillis(); }
From source file:TimePeriod.java
/** * Setzt den bis-Wert auf einen der Standard-Typen * // ww w .j ava 2s. c om * @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:org.apache.fontbox.ttf.TTFSubsetter.java
private void writeLongDateTime(DataOutputStream out, Calendar calendar) throws IOException { // inverse operation of TTFDataStream.readInternationalDate() GregorianCalendar cal = new GregorianCalendar(1904, 0, 1); long millisFor1904 = cal.getTimeInMillis(); long secondsSince1904 = (calendar.getTimeInMillis() - millisFor1904) / 1000L; out.writeLong(secondsSince1904);/*ww w.j av a 2 s . co m*/ }