List of usage examples for org.joda.time DateTimeZone getDefault
public static DateTimeZone getDefault()
From source file:divconq.util.TimeUtil.java
License:Open Source License
/** * get the DST end transition for a given year * /*from w w w . j a v a2 s. c o m*/ * @param year the year to use, e.g. 2012 * @return datetime of the end transition */ public static DateTime endDST(int year) { DateTimeZone zone = DateTimeZone.getDefault(); return new DateTime(zone.previousTransition(new DateTime(year + 1, 1, 1, 0, 0, 0, 0, zone).getMillis())); }
From source file:edu.mit.media.funf.funfohmage.MainPipeline.java
License:Open Source License
private void uploadMobility(String accelerometer, String location, String wifi) { if (mApi == null) setOhmageApi(new OhmageApi(this)); //sendBroadcast(new Intent(UploadService.MOBILITY_UPLOAD_STARTED)); boolean uploadSensorData = true; SharedPreferencesHelper helper = new SharedPreferencesHelper(this); String username = helper.getUsername(); String hashedPassword = helper.getHashedPassword(); long uploadAfterTimestamp = helper.getLastMobilityUploadTimestamp(); if (uploadAfterTimestamp == 0) { uploadAfterTimestamp = helper.getLoginTimestamp(); }//from w ww.j av a2 s . c om Log.w("dony", "user name" + username); //Log.w("dony","hashed"+hashedPassword); //Log.w("dony","uploadTS"+uploadAfterTimestamp); Long now = System.currentTimeMillis(); //Cursor c = MobilityInterface.getMobilityCursor(this, uploadAfterTimestamp); OhmageApi.UploadResponse response = new OhmageApi.UploadResponse(OhmageApi.Result.SUCCESS, null); JSONArray mobilityJsonArray = new JSONArray(); JSONObject mobilityPointJson = new JSONObject(); try { JSONObject acc_json = new JSONObject(accelerometer); JSONObject location_json = new JSONObject(location); JSONObject wifi_json = new JSONObject(wifi); JSONObject location_inner_json = location_json.getJSONObject("LOCATION"); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // Long time = Long.parseLong(c.getString(c.getColumnIndex(MobilityInterface.KEY_TIME))); // if (i == limit - 1) // { // uploadAfterTimestamp = time; // } UUID id = UUID.randomUUID(); mobilityPointJson.put("id", id.toString()); mobilityPointJson.put("time", System.currentTimeMillis()); mobilityPointJson.put("timezone", DateTimeZone.getDefault().getID()); mobilityPointJson.put("mode", "still"); if (uploadSensorData) { mobilityPointJson.put("subtype", "sensor_data"); JSONObject dataJson = new JSONObject(); dataJson.put("mode", "still"); if (location_inner_json.getBoolean("mHasSpeed")) { try { double speed = Double.parseDouble(location_inner_json.getString("mSpeed")); dataJson.put("speed", speed); } catch (NumberFormatException e) { dataJson.put("speed", (double) (-1)); } catch (JSONException e) { dataJson.put("speed", (double) (-1)); } } else { dataJson.put("speed", (float) (-1)); } JSONArray x_array = acc_json.getJSONArray("X"); JSONArray y_array = acc_json.getJSONArray("Y"); JSONArray z_array = acc_json.getJSONArray("Z"); JSONArray ts_array = acc_json.getJSONArray("EVENT_TIMESTAMP"); JSONArray accel_data_array = new JSONArray(); int start_index = 0; long ts_end = 0; if (ts_array.length() > 0) { ts_end = ts_array.getLong(ts_array.length() - 1); } for (int i = ts_array.length() - 2; i >= 0; i--) { if ((ts_end - ts_array.getLong(i)) > 1000000000L) { start_index = i; //Log.i("dony","Stopping at : "+start_index); continue; } //Log.i("dony","diff "+(ts_end - ts_array.getLong(i))/1000000L); } //Log.i("dony","Number of values: "+(x_array.length()- start_index)); //Log.i("dony","Total Number of values: "+x_array.length()); for (int i = start_index; i < x_array.length(); i++) { JSONObject accel_data_json = new JSONObject(); accel_data_json.put("x", x_array.getDouble(i)); accel_data_json.put("y", y_array.getDouble(i)); accel_data_json.put("z", z_array.getDouble(i)); accel_data_array.put(accel_data_json); } dataJson.put("accel_data", accel_data_array); JSONObject wifiJson = new JSONObject(); // wifiJson.put("time", wifi_json.getLong("TIMESTAMP")); wifiJson.put("time", System.currentTimeMillis()); wifiJson.put("timezone", DateTimeZone.getDefault().getID()); JSONArray scan_array = wifi_json.getJSONArray("SCAN_RESULTS"); JSONArray scan_data_array = new JSONArray(); for (int i = 0; i < scan_array.length(); i++) { JSONObject scan_element_json = new JSONObject(); JSONObject scan_input_json = scan_array.getJSONObject(i); scan_element_json.put("ssid", scan_input_json.getString("BSSID")); scan_element_json.put("strength", scan_input_json.getDouble("level")); scan_data_array.put(scan_element_json); } wifiJson.put("scan", scan_data_array); dataJson.put("wifi_data", wifiJson); mobilityPointJson.put("data", dataJson); } else { mobilityPointJson.put("subtype", "mode_only"); mobilityPointJson.put("mode", "still"); } //String locationStatus = c.getString(c.getColumnIndex(MobilityInterface.KEY_STATUS)); JSONObject locationJson = new JSONObject(); if (location_inner_json.getBoolean("mHasAccuracy")) { mobilityPointJson.put("location_status", "valid"); locationJson.put("accuracy", location_inner_json.getDouble("mAccuracy")); } else { mobilityPointJson.put("location_status", "inaccurate"); locationJson.put("accuracy", "NaN"); } try { locationJson.put("latitude", location_inner_json.getDouble("mLatitude")); } catch (NumberFormatException e) { locationJson.put("latitude", "NaN"); } catch (JSONException e) { locationJson.put("latitude", "NaN"); } try { locationJson.put("longitude", location_inner_json.getDouble("mLongitude")); } catch (NumberFormatException e) { locationJson.put("longitude", "NaN"); } catch (JSONException e) { locationJson.put("longitude", "NaN"); } locationJson.put("provider", location_inner_json.getString("mProvider")); try { locationJson.put("accuracy", location_inner_json.getDouble("mAccuracy")); } catch (NumberFormatException e) { locationJson.put("accuracy", "NaN"); } catch (JSONException e) { locationJson.put("accuracy", "NaN"); } // locationJson.put("time", location_json.getLong("TIMESTAMP")); locationJson.put("time", location_inner_json.getDouble("mTime")); locationJson.put("timezone", DateTimeZone.getDefault().getID()); mobilityPointJson.put("location", locationJson); mobilityJsonArray.put(mobilityPointJson); } catch (JSONException e) { Log.e(TAG, "error creating mobility json", e); // if(isBackground) // NotificationHelper.showMobilityErrorNotification(this); throw new RuntimeException(e); } TAG = "dony"; //Database Test datasource = new SensorDataSource(this); datasource.open(); String dataToUpload = mobilityJsonArray.toString(); Boolean currentData_bool = true; SensorData tempData = null; while (true) { response = mApi.mobilityUpload(Config.DEFAULT_SERVER_URL, username, hashedPassword, OhmageApi.CLIENT_NAME, dataToUpload); SharedPreferences.Editor editor = getSystemPrefs().edit(); editor.putLong(DATABASE_COUNT_KEY, datasource.count()); editor.commit(); Log.i(TAG, "Number of database points:" + datasource.count()); if (response.getResult().equals(OhmageApi.Result.SUCCESS)) { Log.i(TAG, "Successfully uploaded 1 mobility points:" + dataToUpload); if (currentData_bool) { currentData_bool = false; Log.i(TAG, "Finished current. Starting past"); } else { Log.i(TAG, " data to be deleted: " + tempData.getData()); datasource.deleteData(tempData); Log.i(TAG, "Successfully uploaded 1 past"); } helper.putLastMobilityUploadTimestamp(uploadAfterTimestamp); List<SensorData> values = datasource.getAllData(); if (values == null || values.size() == 0) break; else { tempData = values.get(0); dataToUpload = tempData.getData(); } Log.i(TAG, "number of values:" + values.size() + " data: " + tempData.getData()); } else { Log.e(TAG, "Failed to upload mobility points. Cancelling current round of mobility uploads."); switch (response.getResult()) { case FAILURE: Log.e(TAG, "Upload failed due to error codes: " + Utilities.stringArrayToString(response.getErrorCodes(), ", ")); boolean isAuthenticationError = false; boolean isUserDisabled = false; for (String code : response.getErrorCodes()) { if (code.charAt(1) == '2') { isAuthenticationError = true; if (code.equals("0201")) { isUserDisabled = true; } } } if (isUserDisabled) { new SharedPreferencesHelper(this).setUserDisabled(true); } // if (isBackground) // { // if (isAuthenticationError) { // NotificationHelper.showAuthNotification(this); // } else { // NotificationHelper.showMobilityErrorNotification(this); // } // } break; case INTERNAL_ERROR: Log.e(TAG, "Upload failed due to unknown internal error"); // if (isBackground) // NotificationHelper.showMobilityErrorNotification(this); break; case HTTP_ERROR: Log.e(TAG, "Upload failed due to network error"); break; } if (currentData_bool) { datasource.createData(dataToUpload); Log.i(TAG, "Storing in database"); } Log.i(TAG, "Breaking due to Error"); break; } } datasource.close(); //sendBroadcast(new Intent(UploadService.MOBILITY_UPLOAD_FINISHED)); }
From source file:edu.osu.ocio.shibboleth.idp.authn.provider.NotificationLoginSubmodule.java
License:Apache License
/** {@inheritDoc} */ public void run(StatelessLoginServlet servlet, HttpServletRequest request, HttpServletResponse response, StatelessAuthenticationInfo info) throws AuthenticationException { if (!info.isAuthenticated() || request.getParameter("j_notify") != null) { return;// ww w. j a v a 2 s .co m } Cookie cookie = HttpServletHelper.getCookie(request, notifyCookie); Map<String, String> attrs = info.getResolvedAttributes(); String exp = (attrs != null) ? attrs.get(passwordExpiration) : null; if (exp != null) { long now = System.currentTimeMillis(); long timeLeft = activeDirectoryConversion ? convertFromAD(exp) : Long.parseLong(exp); if (log.isDebugEnabled()) { log.debug("password for {} expires at {}", info.getUsername(), new DateTime(timeLeft, DateTimeZone.getDefault())); } timeLeft -= now; if (timeLeft < 0) { log.warn("Password apparently expired, should have been reported as a login error"); } else if (timeLeft > getNotifyWindow()) { if (cookie != null) { log.debug("Password expiration not imminent, clearing cookie"); cookie.setValue(""); cookie.setMaxAge(0); cookie.setSecure(true); cookie.setPath(request.getContextPath() + request.getServletPath()); response.addCookie(cookie); } } else { long lastNotify = (cookie != null) ? Long.parseLong(cookie.getValue()) : 0; if (now - lastNotify > getNotifyInterval()) { log.debug("Triggering password expiration warning, saving login identity to SSO cookie"); try { servlet.saveToCookie(request, response, info); } catch (DataSealerException e) { log.error("Skipping notification due to error preserving login identity: {}", e.getMessage()); return; } if (cookie == null) { cookie = new Cookie(notifyCookie, Long.toString(now)); } else { cookie.setValue(Long.toString(now)); } cookie.setMaxAge(getNotifyWindow() / 1000); cookie.setSecure(true); cookie.setPath(request.getContextPath() + request.getServletPath()); response.addCookie(cookie); response.setContentType("text/html"); response.setHeader("Cache-Control", "content=\"no-store,no-cache,must-revalidate\""); response.setHeader("Pragma", "no-cache"); response.setHeader("Expires", "-1"); VelocityContext vCtx = new VelocityContext(); vCtx.put("authnInfo", info); vCtx.put("servletPath", request.getContextPath() + request.getServletPath()); vCtx.put("passwordExpiration", DateTimeFormat.forPattern("EEEE MMMM d, h:mm a").print(now + timeLeft)); try { Template template = velocity.getTemplate(templateName); PrintWriter writer = response.getWriter(); template.merge(vCtx, writer); writer.flush(); } catch (Exception e) { log.error(e.getMessage()); throw new AuthenticationException("Error while processing notification template.", e); } } } } }
From source file:energy.usef.core.adapter.YodaTimeAdapter.java
License:Apache License
/** * Transforms a String (xsd:dateTime) to a {@link LocalDateTime}. * // ww w .ja v a 2 s . c om * @param dateTimeString A String (xsd:dateTime) * @return {@link LocalDateTime} */ public static LocalDateTime parseDateTime(String dateTimeString) { if (StringUtils.isNotEmpty(dateTimeString)) { return new DateTime(dateTimeString).withZone(DateTimeZone.getDefault()).toLocalDateTime(); } return null; }
From source file:es.collectserv.handler.LocalDateTypeHandler.java
License:Apache License
public Object getResult(ResultSet rs, String columnName) throws SQLException { Date date = rs.getDate(columnName); if (date != null) { // Se toma la fecha del sistema. LocalDate d = new LocalDate(date.getTime(), DateTimeZone.getDefault()); return d; } else {// w ww .jav a 2 s.c o m return null; } }
From source file:eu.europa.ec.fisheries.uvms.common.DateUtils.java
License:Open Source License
public static Date getNowDateUTC() { DateTimeZone zone = DateTimeZone.getDefault(); long utc = zone.convertLocalToUTC(new Date().getTime(), false); return new Date(utc); }
From source file:eu.europa.ec.fisheries.uvms.movement.util.DateUtil.java
License:Open Source License
public static Date parsePositionTime(XMLGregorianCalendar positionTime) { if (positionTime != null) { DateTimeZone localTZ = DateTimeZone.getDefault(); long eventMillsInUTCTimeZone = localTZ .convertLocalToUTC(positionTime.toGregorianCalendar().getTime().getTime(), false); DateTime evenDateTimeInUTCTimeZone = new DateTime(eventMillsInUTCTimeZone); return evenDateTimeInUTCTimeZone.toDate(); }/*ww w . j a va2 s . co m*/ return null; }
From source file:eu.europa.ec.fisheries.uvms.movement.util.DateUtil.java
License:Open Source License
public static Date convertDateTimeInUTC(String dateTimeInUTC, String pattern) { if (dateTimeInUTC != null) { SimpleDateFormat sdf = new SimpleDateFormat(pattern); try {// w ww .j av a2s .c o m Date theDate = sdf.parse(dateTimeInUTC); DateTimeZone localTZ = DateTimeZone.getDefault(); long eventMillsInUTCTimeZone = localTZ.convertLocalToUTC(theDate.getTime(), false); DateTime evenDateTimeInUTCTimeZone = new DateTime(eventMillsInUTCTimeZone); return evenDateTimeInUTCTimeZone.toDate(); } catch (java.text.ParseException e) { LOG.info("Could not parse dateTimeInUTC: " + dateTimeInUTC + " with pattern: " + pattern + ". Trying next pattern"); } } return null; }
From source file:fi.hsl.parkandride.core.domain.DefaultTimeZoneDateTimeSerializer.java
License:EUPL
@Override public void serialize(DateTime value, JsonGenerator jgen, SerializerProvider provider) throws IOException { DateTimeSerializer serializer = new DateTimeSerializer(formatterWithTimeZone(DateTimeZone.getDefault())); serializer.serialize(value, jgen, provider); }
From source file:gobblin.source.DatePartitionedAvroFileSource.java
License:Apache License
private void initDatePartitionFromPattern(State state) { String partitionPattern = null; try {/*from w w w. ja v a2s . c o m*/ partitionPattern = state.getProp(DATE_PARTITIONED_SOURCE_PARTITION_PATTERN); if (partitionPattern != null) { this.partitionPatternFormatter = DateTimeFormat.forPattern(partitionPattern) .withZone(DateTimeZone.getDefault()); this.incrementalUnit = DatePartitionType.getLowestIntervalUnit(partitionPattern).getDurationType(); } } catch (Exception e) { throw new IllegalArgumentException("Invalid source partition pattern: " + partitionPattern, e); } }