List of usage examples for org.joda.time DateTimeZone getDefault
public static DateTimeZone getDefault()
From source file:com.thinkbiganalytics.metadata.jobrepo.nifi.provenance.NifiStatsJmsReceiver.java
License:Apache License
/** * the BulletinDTO comes back from nifi as a Date object in the year 1970 * We need to convert this to the current date and account for DST * * @param b the bulletin//from ww w .j av a 2 s . co m */ private DateTime getAdjustBulletinDateTime(BulletinDTO b) { DateTimeZone defaultZone = DateTimeZone.getDefault(); int currentOffsetMillis = defaultZone.getOffset(DateTime.now().getMillis()); double currentOffsetHours = (double) currentOffsetMillis / 1000d / 60d / 60d; long bulletinOffsetMillis = DateTimeZone.getDefault().getOffset(b.getTimestamp().getTime()); double bulletinOffsetHours = (double) bulletinOffsetMillis / 1000d / 60d / 60d; DateTime adjustedTime = new DateTime(b.getTimestamp()).withDayOfYear(DateTime.now().getDayOfYear()) .withYear(DateTime.now().getYear()); int adjustedHours = 0; if (currentOffsetHours != bulletinOffsetHours) { adjustedHours = new Double(bulletinOffsetHours - currentOffsetHours).intValue(); adjustedTime = adjustedTime.plusHours(-adjustedHours); } return adjustedTime; }
From source file:com.wellsandwhistles.android.redditsp.common.SRTime.java
License:Open Source License
public static String formatDurationFrom(final Context context, final long startTime) { final String space = " "; final String comma = ","; final String separator = comma + space; final long endTime = utcCurrentTimeMillis(); final DateTime dateTime = new DateTime(endTime); final DateTime localDateTime = dateTime.withZone(DateTimeZone.getDefault()); Period period = new Duration(startTime, endTime).toPeriodTo(localDateTime); PeriodFormatter periodFormatter = new PeriodFormatterBuilder().appendYears().appendSuffix(space) .appendSuffix(context.getString(R.string.time_year), context.getString(R.string.time_years)) .appendSeparator(separator).appendMonths().appendSuffix(space) .appendSuffix(context.getString(R.string.time_month), context.getString(R.string.time_months)) .appendSeparator(separator).appendDays().appendSuffix(space) .appendSuffix(context.getString(R.string.time_day), context.getString(R.string.time_days)) .appendSeparator(separator).appendHours().appendSuffix(space) .appendSuffix(context.getString(R.string.time_hour), context.getString(R.string.time_hours)) .appendSeparator(separator).appendMinutes().appendSuffix(space) .appendSuffix(context.getString(R.string.time_min), context.getString(R.string.time_mins)) .appendSeparator(separator).appendSeconds().appendSuffix(space) .appendSuffix(context.getString(R.string.time_sec), context.getString(R.string.time_secs)) .appendSeparator(separator).appendMillis().appendSuffix(space) .appendSuffix(context.getString(R.string.time_ms)).toFormatter(); String duration = periodFormatter.print(period.normalizedStandard(PeriodType.yearMonthDayTime())); List<String> parts = Arrays.asList(duration.split(comma)); if (parts.size() >= 2) { duration = parts.get(0) + comma + parts.get(1); }//from ww w . java 2s . c o m return String.format(context.getString(R.string.time_ago), duration); }
From source file:com.wso2telco.dep.reportingservice.dao.BillingDAO.java
License:Open Source License
/** * Convert to local time./*w w w .j ava 2 s .c o m*/ * * @param timeOffset the time offset * @param time the time * @return the string */ public String convertToLocalTime(String timeOffset, String time) { Integer offsetValue = Integer.parseInt(timeOffset); log.debug("Offset value = " + offsetValue); DateTimeZone systemTimeZone = DateTimeZone.getDefault(); log.debug("system time zone " + systemTimeZone.toString()); DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); DateTime systemDateTime = formatter.parseDateTime(time); log.debug("system date time " + systemDateTime.toString()); systemDateTime = systemDateTime.withZoneRetainFields(systemTimeZone); log.debug("system date time after adding systemtimezone === " + systemDateTime.toString()); int hours = -1 * offsetValue / 60; int minutes = offsetValue % 60; minutes = Math.abs(minutes); DateTimeZone localTimeZone = DateTimeZone.forOffsetHoursMinutes(hours, minutes); log.debug("Local time zone ==== " + localTimeZone.toString()); DateTime convertedDateTime = systemDateTime.withZone(localTimeZone); String convertedDateTimeString = formatter.print(convertedDateTime); log.debug("converted time :" + convertedDateTimeString); return convertedDateTimeString; }
From source file:com.xpn.xwiki.plugin.jodatime.JodaTimePlugin.java
License:Open Source License
/** * @see org.joda.time.DateTimeZone#getDefault() */ public DateTimeZone getServerTimezone() { return DateTimeZone.getDefault(); }
From source file:com.yahoo.bard.webservice.application.JerseyTestBinder.java
License:Apache License
/** * Constructor with more control over auto-start and the application state it uses. * * @param doStart Will auto-start test harness after constructing if true, must be manually started if false. * @param state Application state to load for testing * @param resourceClasses Resource classes for Jersey to load *///w w w.ja v a 2s . c o m public JerseyTestBinder(boolean doStart, ApplicationState state, Class<?>... resourceClasses) { this.state = state; //Initializing the Sketch field converter FieldConverterSupplier.sketchConverter = initializeSketchConverter(); //Initialize the metrics filter helper FieldConverterSupplier.metricsFilterSetBuilder = initializeMetricsFilterSetBuilder(); // Set up the web services buildWebServices(); // Pin the default timezone to UTC so that we use the same timezone no matter where tests run previousDateTimeZone = DateTimeZone.getDefault(); DateTimeZone.setDefault(DateTimeZone.UTC); // Fill in the binder factory testBinderFactory = buildBinderFactory(getDimensionConfiguration(), getMetricLoader(), getTableLoader(), state); this.binder = (AbstractBinder) (testBinderFactory.buildBinder()); // Configure and register the resources this.config = new ResourceConfig(); // Order matters. First check if BardLoggingFilter is requested boolean skipWrapper = false; for (Class<?> cls : resourceClasses) { if (cls.getSimpleName().equals(BardLoggingFilter.class.getSimpleName())) { skipWrapper = true; } } // If BardLoggingFilter is not requested, use a wrapper instead to enable logging of the information that is // potentially recorded in the resources that are registered if (skipWrapper) { this.config.registerClasses(resourceClasses); } else { this.config.register(getLoggingFilter(), 1); // Now register the requested classes for (Class<?> cls : resourceClasses) { this.config.register(cls, 5); } } this.config .register(new InstrumentedResourceMethodApplicationListener(MetricRegistryFactory.getRegistry())); this.config.register(this.binder); registerMetricsAppender(); // Create and set up the test harness this.harness = new JerseyTest() { @Override protected Application configure() { // Find first available port. forceSet(TestProperties.CONTAINER_PORT, RANDOM_PORT); return config; } }; if (doStart) { start(); } }
From source file:com.yahoo.bard.webservice.util.DateTimeUtils.java
License:Apache License
/** * Given a granularity, produce a time zone. * * @param granularity The granularity's time zone, or if there isn't one, the default time zone * * @return A time zone/* w w w .ja v a2 s . c om*/ */ public static DateTimeZone getTimeZone(Granularity granularity) { return (granularity instanceof ZonedTimeGrain) ? ((ZonedTimeGrain) granularity).getTimeZone() : DateTimeZone.getDefault(); }
From source file:ddf.metrics.reporting.internal.rrd4j.RrdMetricsRetriever.java
License:Open Source License
private String getTimestamp(MutableDateTime chunkStart, MutableDateTime chunkEnd, int columnCounter, SUMMARY_INTERVALS summaryInterval) { StringBuilder title = new StringBuilder(); title.append(StringUtils.capitalize(summaryInterval.toString())).append(" ").append(columnCounter) .append("\n"); String timestamp = SUMMARY_TIMESTAMP; switch (summaryInterval) { case minute:/*from w w w.ja v a2s . c om*/ case hour: break; case day: case week: timestamp = "dd-MM-y"; break; case month: timestamp = "MM-y"; break; } title.append(chunkStart.toDateTime(DateTimeZone.getDefault()).toString(timestamp)).append(" to ") .append(chunkEnd.toDateTime(DateTimeZone.getDefault()).toString(timestamp)); return title.toString(); }
From source file:de.brazzy.nikki.ScanWorker.java
License:Open Source License
@Override protected void process(List<Void> chunks) { synchronized (zoneLock) { zone = dialogs.askTimeZone(DateTimeZone.getDefault()); if (zone != null) { zoneLock.notifyAll();//from www .j a v a 2s . c o m } else { thread.interrupt(); } } }
From source file:de.javakaffee.kryoserializers.jodatime.JodaDateTimeSerializer.java
License:Apache License
@Override public void write(final Kryo kryo, final Output output, final DateTime obj) { output.writeLong(obj.getMillis(), true); final String chronologyId = getChronologyId(obj.getChronology()); output.writeString(chronologyId == null ? "" : chronologyId); if (obj.getZone() != null && obj.getZone() != DateTimeZone.getDefault()) output.writeString(obj.getZone().getID()); else/*from w w w . java2 s .co m*/ output.writeString(""); }
From source file:de.javakaffee.kryoserializers.jodatime.JodaDateTimeSerializer.java
License:Apache License
private DateTimeZone readTimeZone(final Input input) { final String tz = input.readString(); return "".equals(tz) ? DateTimeZone.getDefault() : DateTimeZone.forID(tz); }