List of usage examples for org.joda.time DateTimeZone UTC
DateTimeZone UTC
To view the source code for org.joda.time DateTimeZone UTC.
Click Source Link
From source file:com.cyngn.vertx.opentsdb.service.MetricsParser.java
License:Apache License
/** * Given the raw metric data create an OpenTsDb formatted string. * * @param name the metric name/*from w w w .j a v a 2s . co m*/ * @param value the metric value * @param tags the tags string for this data point * @return an OpenTsDb metric string */ public String getMetricString(String name, String value, String tags) { long timestamp = DateTime.now(DateTimeZone.UTC).toDate().getTime(); return (hasPrefix) ? String.format("put %s.%s %d %s %s\n", prefix, name, timestamp, value, tags) : String.format("put %s %d %s %s\n", name, timestamp, value, tags); }
From source file:com.datastax.driver.extras.codecs.joda.DateTimeCodec.java
License:Apache License
@Override protected DateTime parseAndSetField(String input, DateTime target, int index) { if (index == 0) { // strip enclosing single quotes, if any if (ParseUtils.isQuoted(input)) input = ParseUtils.unquote(input); if (isLongLiteral(input)) { try { long millis = Long.parseLong(input); return new DateTime(millis); } catch (NumberFormatException e) { throw new InvalidTypeException( String.format("Cannot parse timestamp value from \"%s\"", input)); }//from w w w . j a v a 2 s . c o m } try { return parser.parseDateTime(input); } catch (RuntimeException e) { throw new InvalidTypeException(String.format("Cannot parse timestamp value from \"%s\"", target)); } } if (index == 1) { String zoneId = varchar().parse(input); // Joda time does not recognize "Z" if ("Z".equals(zoneId)) return target.withZone(DateTimeZone.UTC); return target.withZone(DateTimeZone.forID(zoneId)); } throw new IndexOutOfBoundsException("Tuple index out of bounds. " + index); }
From source file:com.digi.android.wva.DashboardActivity.java
License:Mozilla Public License
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: navigateBackToDevices();//from ww w . j av a2 s .c om return true; case R.id.sync_time: Log.d(TAG, "Executing time sync."); WvaApplication app = (WvaApplication) getApplication(); if (app.getDevice() != null) app.getDevice().setTime(DateTime.now(DateTimeZone.UTC), new WvaCallback<DateTime>() { @Override public void onResponse(Throwable error, DateTime response) { Log.d(TAG, "Time sync error: " + error); String message; if (error == null) message = "Time sync successful."; else message = "Time sync: " + error; Toast.makeText(DashboardActivity.this, message, Toast.LENGTH_SHORT).show(); } }); else Log.d(TAG, "Can't execute time sync: no Device in WvaApplication"); return true; // startActivityForResult should make it so that backing out (i.e. finish()ing) // from the launched activities returns us here to DashboardActivity case R.id.action_settings: startActivityForResult(new Intent(this, SettingsActivity.class), 0); return true; case R.id.launch_chart: startActivityForResult(new Intent(this, ChartActivity.class), 0); return true; case R.id.fault_codes: startActivity(new Intent(this, FaultCodeActivity.class)); return true; } return false; }
From source file:com.digi.wva.internal.Hardware.java
License:Mozilla Public License
/** * Underlying implementation of {@link com.digi.wva.WVA#setTime(DateTime, WvaCallback)} * * @throws JSONException if an error occurs while creating the request *///from w w w . j av a 2 s.com public void setTime(final DateTime newTime, final WvaCallback<DateTime> cb) throws JSONException { JSONObject time = new JSONObject(); final DateTime newTimeUTC = newTime.toDateTime(DateTimeZone.UTC); final String timestamp = format.print(newTimeUTC); Log.i(TAG, "Sending timestamp down: " + timestamp); time.put("time", timestamp); httpClient.put(TIME_BASE, time, new HttpClient.ExpectEmptyCallback() { @Override public void onSuccess() { if (cb != null) { cb.onResponse(null, newTimeUTC); } } @Override public void onBodyNotEmpty(String body) { Log.e(TAG, "setTime got unexpected response body content:\n" + body); onFailure(new Exception("Unexpected response body: " + body)); } @Override public void onFailure(Throwable error) { Log.e(TAG, "Failed to set WVA device time to " + timestamp, error); if (cb != null) { cb.onResponse(error, newTimeUTC); } } }); }
From source file:com.digi.wva.test_auxiliary.SimulatedEventChannel.java
License:Mozilla Public License
/** * Construct a template event channel JSON object, containing a timestamp and * with the top-level key corresponding to the event type ("data" or "alarm"). * @param type the event type to use/*w w w . j a v a 2 s . c o m*/ * @return a template JSON object * @throws JSONException if there is an error in building this JSON */ private JSONObject buildStub(EventFactory.Type type) throws JSONException { JSONObject stub = new JSONObject(); String timestamp = formatter.print(DateTime.now(DateTimeZone.UTC)); // Add inner object stub.put(type == EventFactory.Type.SUBSCRIPTION ? "data" : "alarm", new JSONObject().put("timestamp", timestamp)); return stub; }
From source file:com.dtstack.jlogstash.utils.BasePluginUtil.java
License:Apache License
public void addFields(Map<String, Object> event, Map<String, Object> addFields) { Set<Map.Entry<String, Object>> sets = addFields.entrySet(); for (Map.Entry<String, Object> entry : sets) { String key = entry.getKey(); if (event.get(key) == null) { Object value = entry.getValue(); event.put(key, value);//from w ww. j av a2 s . c o m if (event.get(value) != null) { event.put(key, event.get(value)); } else if (value instanceof String) { String vv = value.toString(); if (vv.indexOf(".") > 0) { String[] vs = vv.split("\\."); Object oo = event; for (int i = 0; i < vs.length; i++) { oo = loopObject(vs[i], oo); if (oo == null) break; } if (oo != null) event.put(key, oo); } else if ("%{hostname}%".equals(vv)) { event.put(key, Public.getHostName()); } else if ("%{timestamp}%".equals(vv)) { event.put(key, Public.getTimeStamp(null)); } else if ("%{timestamp-utc}%".equals(vv)) { event.put(key, Public.getTimeStamp(DateTimeZone.UTC)); } else if ("%{ip}%".equals(vv)) { event.put(key, Public.getHostAddress()); } } } } }
From source file:com.ecofactor.qa.automation.util.DateUtil.java
License:Open Source License
/** * Gets the calendar.// ww w. j a v a 2s . com * @param timeStamp the time stamp * @param dateFormat the date format * @return the calendar * @throws ParseException the parse exception */ public static Calendar getCalendar(String timeStamp, final String dateFormat) throws ParseException { DateTime dt = new DateTime(DateTimeZone.UTC); Calendar calendar = dt.toCalendar(Locale.ENGLISH); SimpleDateFormat sdf = new SimpleDateFormat(DATE_FMT_FULL, Locale.ENGLISH); Date date = sdf.parse(timeStamp); calendar.setTime(date); return calendar; }
From source file:com.ecofactor.qa.automation.util.DateUtil.java
License:Open Source License
/** * Gets the current time stamp./* w w w . j av a 2s . c o m*/ * @return the current time stamp */ public static String getUTCCurrentTimeStamp() { DateTime startDate = new DateTime(DateTimeZone.UTC); DateTimeFormatter fmt = DateTimeFormat.forPattern(DATE_FMT_FULL); return fmt.print(startDate); }
From source file:com.ecofactor.qa.automation.util.DateUtil.java
License:Open Source License
/** * Gets the uTC current time stamp.// www.ja v a 2 s.c om * @param pattern the pattern * @return the uTC current time stamp */ public static String getUTCCurrentTimeStamp(String pattern) { DateTime startDate = new DateTime(DateTimeZone.UTC); DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern); return fmt.print(startDate); }
From source file:com.ecofactor.qa.automation.util.DateUtil.java
License:Open Source License
/** * Gets the UTC calendar.//from w w w .j av a 2 s .c om * @return the UTC calendar */ public static Calendar getUTCCalendar() { DateTime dt = new DateTime(DateTimeZone.UTC); Calendar utcCalendar = dt.toCalendar(Locale.ENGLISH); LOGGER.debug("Current UTC Date " + formatToUTC(utcCalendar, DATE_FMT_FULL_TZ)); return utcCalendar; }