List of usage examples for java.util GregorianCalendar get
public int get(int field)
From source file:org.apache.unomi.services.services.ProfileServiceImpl.java
private GregorianCalendar getMonth(int offset) { GregorianCalendar gc = new GregorianCalendar(); gc = new GregorianCalendar(gc.get(Calendar.YEAR), gc.get(Calendar.MONTH), 1); gc.add(Calendar.MONTH, offset); return gc;/* w w w.ja va 2 s . c om*/ }
From source file:ca.mudar.parkcatcher.ui.fragments.DetailsFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { final Resources res = getResources(); if (item.getItemId() == R.id.menu_favorites_toggle) { onCheckedChanged(mIsStarred);/*w ww . j av a2s. c om*/ mIsStarred = (mIsStarred ? false : true); // Toggle value getSherlockActivity().invalidateOptionsMenu(); return true; } else if (item.getItemId() == R.id.menu_map) { final Intent intent = new Intent(getActivity(), MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.putExtra(Const.INTENT_EXTRA_GEO_LAT, mGeoLat); intent.putExtra(Const.INTENT_EXTRA_GEO_LNG, mGeoLng); intent.putExtra(Const.INTENT_EXTRA_POST_ID, mIdPost); startActivity(intent); return true; } else if (item.getItemId() == R.id.menu_reminder) { parkingApp.showToastText(R.string.toast_todo_reminder, Toast.LENGTH_LONG); return true; } else if (item.getItemId() == R.id.menu_directions) { if ((Double.compare(mGeoLat, Double.MIN_VALUE) != 0) && (Double.compare(mGeoLng, Double.MIN_VALUE) != 0)) { /** * Get directions using Intents. */ try { final Uri uriNavigation = Uri .parse(String.format(Const.URI_INTENT_NAVIGATION, mGeoLat, mGeoLng)); final Intent intent = new Intent(Intent.ACTION_VIEW, uriNavigation); startActivity(intent); } catch (Exception e) { e.printStackTrace(); String sAddr = ""; Location userLocation = parkingApp.getLocation(); if (userLocation != null) { sAddr = Double.toString(userLocation.getLatitude()) + "," + Double.toString(userLocation.getLongitude()); } final String urlGmaps = String.format(Const.URL_GMAPS_DIRECTIONS, sAddr, mGeoLat + "," + mGeoLng); final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlGmaps)); startActivity(intent); } } return true; } else if (item.getItemId() == R.id.menu_streetview) { if ((Double.compare(mGeoLat, Double.MIN_VALUE) != 0) && (Double.compare(mGeoLng, Double.MIN_VALUE) != 0)) { try { final Uri uriStreetView = Uri .parse(String.format(Const.URI_INTENT_STREETVIEW, mGeoLat, mGeoLng)); final Intent intent = new Intent(Intent.ACTION_VIEW, uriStreetView); startActivity(intent); } catch (NullPointerException e) { e.printStackTrace(); return false; } catch (Exception e) { parkingApp.showToastText(R.string.toast_streetview_error, Toast.LENGTH_LONG); e.printStackTrace(); final Uri uriInstallStreetView = Uri.parse(Const.URI_INSTALL_STREETVIEW); final Intent intent = new Intent(Intent.ACTION_VIEW, uriInstallStreetView); startActivity(intent); return false; } } return true; } else if (item.getItemId() == R.id.menu_share) { final GregorianCalendar parkingCalendar = parkingApp.getParkingCalendar(); final int dayOfWeek = (parkingCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY ? 7 : parkingCalendar.get(Calendar.DAY_OF_WEEK) - 1); final double parkingHour = parkingCalendar.get(Calendar.HOUR_OF_DAY) + Math.round(parkingCalendar.get(Calendar.MINUTE) / 0.6) / 100.00d; // final int duration = parkingApp.getParkingDuration(); final String url = String.format(res.getString(R.string.url_share_post_id), mIdPost, dayOfWeek, parkingHour, parkingApp.getParkingDuration()); final String subject = String.format(res.getString(R.string.details_share_title), url); final String desc = String.format(res.getString(R.string.details_share_subtitle), mShareDesc); final Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); // EXTRA_SUBJECT is not used to allow sharing with SMS instead of // MMS // intent.putExtra(Intent.EXTRA_SUBJECT, subject); intent.putExtra(Intent.EXTRA_TEXT, subject + Const.LINE_SEPARATOR + desc); startActivity(intent); return true; } return (activityHelper.onOptionsItemSelected(item) || super.onOptionsItemSelected(item)); }
From source file:eu.stratosphere.client.web.JobsServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String action = req.getParameter(ACTION_PARAM_NAME); if (action.equals(ACTION_LIST_VALUE)) { GregorianCalendar cal = new GregorianCalendar(); File[] files = destinationDir.listFiles(); Arrays.<File>sort(files, FILE_SORTER); resp.setStatus(HttpServletResponse.SC_OK); resp.setContentType(CONTENT_TYPE_PLAIN); PrintWriter writer = resp.getWriter(); for (int i = 0; i < files.length; i++) { if (!files[i].getName().endsWith(".jar")) { continue; }// ww w . ja v a2 s . c o m cal.setTimeInMillis(files[i].lastModified()); writer.println(files[i].getName() + '\t' + (cal.get(GregorianCalendar.MONTH) + 1) + '/' + cal.get(GregorianCalendar.DAY_OF_MONTH) + '/' + cal.get(GregorianCalendar.YEAR) + ' ' + cal.get(GregorianCalendar.HOUR_OF_DAY) + ':' + cal.get(GregorianCalendar.MINUTE) + ':' + cal.get(GregorianCalendar.SECOND)); } } else if (action.equals(ACTION_DELETE_VALUE)) { String filename = req.getParameter(FILENAME_PARAM_NAME); if (filename == null || filename.length() == 0) { resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); } else { File f = new File(destinationDir, filename); if (!f.exists() || f.isDirectory()) { resp.setStatus(HttpServletResponse.SC_NOT_FOUND); } f.delete(); resp.setStatus(HttpServletResponse.SC_OK); } } else { resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); } }
From source file:net.kw.shrdlu.grtgtfs.Activities.RiderAlertsActivity.java
/** * Get the latest twitter info. Some of this copied from http://www.vogella.com/articles/AndroidJSON/article.html *//* w w w .j a v a2 s . c om*/ ArrayList<String[]> readTwitterFeed() { final StringBuilder builder = new StringBuilder(); final HttpClient client = new DefaultHttpClient(); final HttpGet httpGet = new HttpGet(TwitterURL + TwitterQry); httpGet.setHeader("Authorization", "Bearer " + AccessToken); try { final HttpResponse response = client.execute(httpGet); final StatusLine statusLine = response.getStatusLine(); final int statusCode = statusLine.getStatusCode(); if (statusCode == 200) { final HttpEntity entity = response.getEntity(); final InputStream content = entity.getContent(); final BufferedReader reader = new BufferedReader(new InputStreamReader(content)); String line; while ((line = reader.readLine()) != null) { builder.append(line); } reader.close(); content.close(); // Result is an array of tweets final JSONArray arr = (JSONArray) new JSONTokener(builder.toString()).nextValue(); final ArrayList<String[]> tweets = new ArrayList<>(); // Need to grok dates of form "created_at": "Thu, 15 Nov 2012 18:27:17 +0000" final SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss ZZZZZ yyyy"); dateFormat.setLenient(true); for (int i = 0; i < arr.length(); i++) { final String text = arr.getJSONObject(i).get("text").toString(); String tweettime = arr.getJSONObject(i).get("created_at").toString(); // Extract & reformat the date Date created; final GregorianCalendar cal = new GregorianCalendar(); try { created = dateFormat.parse(tweettime); cal.setTime(created); String day, mon; day = cal.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault()); mon = cal.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault()); tweettime = String.format("%s %02d:%02d - %s %d", day, cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), mon, cal.get(Calendar.DAY_OF_MONTH)); } catch (final Exception e) { Log.d(TAG, "Exception: " + e.getMessage() + ", parsing tweet date `" + tweettime + "'"); tweettime = "--:--"; } tweets.add(new String[] { tweettime, text }); } return tweets; } else { Log.d(TAG, "Failed to download twitter info"); } } catch (final ClientProtocolException e) { Log.d(TAG, "ClientProtocolException: " + e.getMessage() + ", Failed to download twitter info"); } catch (final IOException e) { Log.d(TAG, "IOException: " + e.getMessage() + ", Failed to download twitter info"); } catch (final Exception e) { Log.d(TAG, "Exception: " + e.getMessage() + ", Failed to download twitter info"); } return null; }
From source file:org.apache.oodt.cas.metadata.util.PathUtils.java
public static String doDynamicDateReplacement(String string, Metadata metadata) throws CasMetadataException, CommonsException { Pattern datePattern = Pattern.compile( "\\[\\s*DATE\\s*(?:[+-]{1}[^\\.]{1,}?){0,1}\\.\\s*(?:(?:DAY)|(?:MONTH)|(?:YEAR)|(?:UTC)|(?:TAI)){1}\\s*\\]"); Matcher dateMatcher = datePattern.matcher(string); while (dateMatcher.find()) { String dateString = string.substring(dateMatcher.start(), dateMatcher.end()); GregorianCalendar gc = new GregorianCalendar(); // roll the date if roll days was specfied int plusMinusIndex; if ((plusMinusIndex = dateString.indexOf('-')) != -1 || (plusMinusIndex = dateString.indexOf('+')) != -1) { int dotIndex; if ((dotIndex = dateString.indexOf('.', plusMinusIndex)) != -1) { int rollDays = Integer.parseInt( PathUtils.replaceEnvVariables(dateString.substring(plusMinusIndex, dotIndex), metadata) .replaceAll("[\\+\\s]", "")); gc.add(GregorianCalendar.DAY_OF_YEAR, rollDays); } else { throw new CasMetadataException( "Malformed dynamic date replacement specified (no dot separator) - '" + dateString + "'"); }/* w ww . j a v a2 s . c o m*/ } // determine type and make the appropriate replacement String[] splitDate = dateString.split("\\."); if (splitDate.length < 2) { throw new CasMetadataException("No date type specified - '" + dateString + "'"); } String dateType = splitDate[1].replaceAll("[\\[\\]\\s]", ""); String replacement; if (dateType.equals("DAY")) { replacement = StringUtils.leftPad(gc.get(GregorianCalendar.DAY_OF_MONTH) + "", 2, "0"); } else if (dateType.equals("MONTH")) { replacement = StringUtils.leftPad((gc.get(GregorianCalendar.MONTH) + 1) + "", 2, "0"); } else if (dateType.equals("YEAR")) { replacement = gc.get(GregorianCalendar.YEAR) + ""; } else if (dateType.equals("UTC")) { replacement = DateUtils.toString(DateUtils.toUtc(gc)); } else if (dateType.equals("TAI")) { replacement = DateUtils.toString(DateUtils.toTai(gc)); } else { throw new CasMetadataException("Invalid date type specified '" + dateString + "'"); } string = StringUtils.replace(string, dateString, replacement); dateMatcher = datePattern.matcher(string); } return string; }
From source file:org.apache.unomi.services.services.ProfileServiceImpl.java
public Session loadSession(String sessionId, Date dateHint) { Session s = persistenceService.load(sessionId, dateHint, Session.class); if (s == null && dateHint != null) { GregorianCalendar gc = new GregorianCalendar(); gc.setTime(dateHint);//from w ww .j av a 2 s . c o m if (gc.get(Calendar.DAY_OF_MONTH) == 1) { gc.add(Calendar.DAY_OF_MONTH, -1); s = persistenceService.load(sessionId, gc.getTime(), Session.class); } } return s; }
From source file:org.webical.web.component.event.EventForm.java
/** * Create an empty Event and set the start and end times * @return Event/*from ww w. j a v a2 s . c o m*/ */ private EventWrapper createEmptyEvent() { this.formEvent = new Event(); this.eventWrapper = new EventWrapper(formEvent); GregorianCalendar dateCalendar = CalendarUtils.duplicateCalendar(selectedDate); GregorianCalendar timeCalendar = CalendarUtils.newTodayCalendar(dateCalendar.getFirstDayOfWeek()); dateCalendar.set(GregorianCalendar.HOUR_OF_DAY, timeCalendar.get(GregorianCalendar.HOUR_OF_DAY)); dateCalendar.set(GregorianCalendar.MINUTE, timeCalendar.get(GregorianCalendar.MINUTE) / 5 * 5); //Fill the start and end times with proper values eventWrapper.setDtStart(dateCalendar.getTime()); dateCalendar.add(GregorianCalendar.HOUR_OF_DAY, 1); eventWrapper.setDtEnd(dateCalendar.getTime()); return this.eventWrapper; }
From source file:ca.oson.json.gson.functional.DefaultTypeAdaptersTest.java
public void testDefaultGregorianCalendarDeserialization() throws Exception { String json = "{year:2009,month:2,dayOfMonth:11,hourOfDay:14,minute:29,second:23}"; GregorianCalendar cal = oson.fromJson(json, GregorianCalendar.class); assertEquals(2009, cal.get(Calendar.YEAR)); assertEquals(2, cal.get(Calendar.MONTH)); assertEquals(11, cal.get(Calendar.DAY_OF_MONTH)); assertEquals(14, cal.get(Calendar.HOUR_OF_DAY)); assertEquals(29, cal.get(Calendar.MINUTE)); assertEquals(23, cal.get(Calendar.SECOND)); }
From source file:org.accada.epcis.repository.query.Schedule.java
/** * Sets the specified field of the given callendar to the next scheduled * value. Returns whether the new value has been set and is valid. * /*from w w w . j a v a2s. c o m*/ * @param cal * Calendar to adjust. * @param field * Field to adjust. * @return Returns whether the new value has been set and is valid. * @throws ImplementationException * Almost any error. */ private boolean setToNextScheduledValue(final GregorianCalendar cal, final int field) throws ImplementationExceptionResponse { int next; TreeSet<Integer> vals = getValues(field); if (vals.isEmpty()) { next = cal.get(field) + 1; } else { try { // get next scheduled value which is bigger than current int incrValue = cal.get(field) + 1; next = vals.tailSet(new Integer(incrValue)).first().intValue(); } catch (NoSuchElementException nse) { // there is no bigger scheduled value return false; } } if (next > cal.getActualMaximum(field) || next < cal.getActualMinimum(field)) { return false; } // all is well, set it to next cal.set(field, next); return true; }
From source file:org.accada.epcis.repository.query.Schedule.java
/** * Returns true if the second have been successfully set to valid values * within the set minute./*from w w w. j ava 2s . c om*/ * * @param nextSchedule * The current candidate for the result. * @return True if second successfully set to valid values. * @throws ImplementationException * Almost any error. */ private boolean secondMadeValid(final GregorianCalendar nextSchedule) throws ImplementationExceptionResponse { // check whether the second value of the current time is a valid // scheduled second if (!seconds.isEmpty() && !seconds.contains(Integer.valueOf(nextSchedule.get(SECOND)))) { // no current second is not scheduled // set is to the next scheduled second return setToNextScheduledValue(nextSchedule, SECOND); } return true; }