List of usage examples for org.joda.time DateTimeZone getOffset
public final int getOffset(ReadableInstant instant)
From source file:ch.corten.aha.worldclock.TimeZoneInfo.java
License:Open Source License
public static int getTimeDifference(DateTimeZone tz) { int milliseconds = tz.getOffset(DateTimeUtils.currentTimeMillis()); return milliseconds / 60000; }
From source file:ch.corten.aha.worldclock.TimeZoneInfo.java
License:Open Source License
/** * Convert a joda-time {@link org.joda.time.DateTimeZone} to an equivalent Java {@link java.util.TimeZone}. * * @param dateTimeZone a joda-time {@link org.joda.time.DateTimeZone} * @param time the time when the time zones should be equivalent. * @return a Java {@link java.util.TimeZone} with the same offset for the given time. *///from w w w . j a va2 s .c o m public static TimeZone convertToJavaTimeZone(DateTimeZone dateTimeZone, long time) { TimeZone timeZone = dateTimeZone.toTimeZone(); long offset = dateTimeZone.getOffset(time); if (timeZone.getOffset(time) == offset) { return timeZone; } String[] ids = TimeZone.getAvailableIDs((int) offset); Log.d(TZ_ID_TAG, dateTimeZone.getID() + ": " + Arrays.toString(ids)); for (String id : ids) { TimeZone tz = TimeZone.getTimeZone(id); if (tz.getOffset(time) == offset) { timeZone = tz; Log.d(TZ_ID_TAG, "Found time zone " + tz.getID() + " for " + dateTimeZone.getID() + " with offset: " + offset); break; } } return timeZone; }
From source file:com.barchart.feed.ddf.symbol.enums.DDF_TimeZone.java
License:BSD License
private DDF_TimeZone(final String code, final DateTimeZone zone) { this.ord = (byte) ordinal(); this.code = code; // if (code == _Z_) { // this.zone = DateTimeZone.getDefault(); // } else{/*from w w w . java 2 s . c o m*/ // this.zone = DateTimeZone.getDefault(); // } utcOffsetMillis = zone.getOffset(0); this.zone = zone; }
From source file:com.ehdev.chronos.lib.Chronos.java
License:Open Source License
public static DateTime getDateFromStartOfPayPeriod(DateTime StartOfPP, DateTime date) { DateTime newDate;/*from w w w . ja va 2 s .c om*/ DateTimeZone startZone = StartOfPP.getZone(); DateTimeZone endZone = date.getZone(); long dateTime = date.getMillis() - StartOfPP.getMillis(); long offset = endZone.getOffset(date) - startZone.getOffset(StartOfPP); //System.out.println("offset: " + offset); dateTime += offset; //System.out.println("millis diff: " + (dateTime) ); int days = (int) (dateTime / 1000 / 60 / 60 / 24); newDate = StartOfPP.plusDays(days); //System.out.println("Days to add: " + days); return newDate; }
From source file:com.ehdev.chronos.lib.types.holders.PayPeriodHolder.java
License:Open Source License
/** * Will do the calculations for the start and end of the process *///from ww w .ja va2s. c o m public void generate() { //Get the start and end of pay period DateTime startOfPP = gJob.getStartOfPayPeriod(); gDuration = gJob.getDuration(); DateTime endOfPP = DateTime.now(); //Today long duration = endOfPP.getMillis() - startOfPP.getMillis(); DateTimeZone startZone = startOfPP.getZone(); DateTimeZone endZone = endOfPP.getZone(); long offset = endZone.getOffset(endOfPP) - startZone.getOffset(startOfPP); int weeks = (int) ((duration + offset) / 1000 / 60 / 60 / 24 / 7); /* System.out.println("end of pp: " + endOfPP); System.out.println("start of pp: " + startOfPP); System.out.println("dur: " + duration); System.out.println("weeks diff: " + weeks); */ switch (gDuration) { case ONE_WEEK: //weeks = weeks; startOfPP = startOfPP.plusWeeks(weeks); endOfPP = startOfPP.plusWeeks(1); break; case TWO_WEEKS: weeks = weeks / 2; startOfPP = startOfPP.plusWeeks(weeks * 2); endOfPP = startOfPP.plusWeeks(2); break; case THREE_WEEKS: weeks = weeks / 3; startOfPP = startOfPP.plusWeeks(weeks * 3); endOfPP = startOfPP.plusWeeks(3); break; case FOUR_WEEKS: weeks = weeks / 4; startOfPP = startOfPP.plusWeeks(weeks * 4); endOfPP = startOfPP.plusWeeks(4); break; case FULL_MONTH: //in this case, endOfPP is equal to now startOfPP = DateMidnight.now().toDateTime().withDayOfMonth(1); endOfPP = startOfPP.plusMonths(1); break; case FIRST_FIFTEENTH: DateTime now = DateTime.now(); if (now.getDayOfMonth() >= 15) { startOfPP = now.withDayOfMonth(15); endOfPP = startOfPP.plusDays(20).withDayOfMonth(1); } else { startOfPP = now.withDayOfMonth(1); endOfPP = now.withDayOfMonth(15); } break; default: break; } if (startOfPP.isAfter(DateTime.now())) { startOfPP = startOfPP.minusWeeks(getDays() / 7); endOfPP = endOfPP.minusWeeks(getDays() / 7); } gStartOfPP = startOfPP; gEndOfPP = endOfPP; }
From source file:com.ehdev.chronos.lib.types.holders.PunchTable.java
License:Open Source License
public PunchTable(DateTime start, DateTime end, Job inJob) { DateTimeZone startZone = start.getZone(); DateTimeZone endZone = end.getZone(); long offset = endZone.getOffset(end) - startZone.getOffset(start); int days = (int) ((end.getMillis() - start.getMillis() + offset) / 1000 / 60 / 60 / 24); startOfTable = start;/*from www. jav a2 s . c o m*/ try { if (enableLog) Log.d(TAG, "Punch Table Size: " + days); } catch (Exception e) { try { if (enableLog) Log.d(TAG, "Punch Table Size: " + days); if (enableLog) Log.d(TAG, e.getMessage()); } catch (Exception e2) { System.out.println("Punch Table Size: " + days); System.out.println(e.getMessage()); } } if (enableLog) Log.d(TAG, "Start of table: " + start); createTable(inJob, days, start); }
From source file:com.enitalk.controllers.bots.TimeZoneTestr.java
public static void main(String[] args) { Set<String> ids = DateTimeZone.getAvailableIDs(); TreeMultimap<Long, String> map = TreeMultimap.create(); for (String id : ids) { DateTimeZone dz = DateTimeZone.forID(id); int offset = dz.getOffset(DateTime.now().withZone(DateTimeZone.UTC)); map.put(TimeUnit.MILLISECONDS.toMinutes(offset), id); }/*from www. j a v a 2s . c o m*/ ObjectMapper j = new ObjectMapper(); ArrayNode a = j.createArrayNode(); map.keySet().forEach((Long key) -> { a.addObject().set(key.toString(), j.convertValue(map.get(key), ArrayNode.class)); }); System.out.println(a); // System.out.println(map); }
From source file:com.foundationdb.sql.server.ServerValueDecoder.java
License:Open Source License
private static long seconds2000NoTZ(long secs) { long millis = (secs + 946684800) * 1000; // 2000-01-01 00:00:00-UTC. DateTimeZone dtz = DateTimeZone.getDefault(); millis -= dtz.getOffset(millis); return millis; }
From source file:com.foundationdb.sql.server.ServerValueEncoder.java
License:Open Source License
/** Adjust milliseconds since 1970-01-01 00:00:00-UTC to seconds since * 2000-01-01 00:00:00 timezoneless. A conversion from local time * to UTC involves an offset that varies for Summer time. A * conversion from local time to timezoneless just removes the * zone as though all days were the same length. *//*from w ww . j ava2 s . c om*/ private static long seconds2000NoTZ(long millis) { DateTimeZone dtz = DateTimeZone.getDefault(); millis += dtz.getOffset(millis); return millis / 1000 - 946684800; // 2000-01-01 00:00:00-UTC. }
From source file:com.funambol.common.pim.converter.TimeZoneHelper.java
License:Open Source License
/** * Extract time-zone information from a zoneinfo (Olson database) ID and * saves them in the TimeZoneHelper fields. * * @param id the time zone ID according to the zoneinfo (Olson) database * @param from the start of the relevant time interval for the generation of * transitions (an istant expressed as a long) * @param to the end of the relevant time interval for the generation of * transitions (an istant expressed as a long) *//*from ww w.j a v a2 s . co m*/ protected void processID(String id, long from, long to) { DateTimeZone tz = DateTimeZone.forID(id); if (name == null) { // The name could have been set already using TZID // and in this case it is important not to change it name = id; // The Olson ID is perfect as a unique name } basicOffset = tz.getStandardOffset(from); transitions.clear(); if (!tz.isFixed()) { long oldFrom = from; from = fixFrom(tz, basicOffset, oldFrom); //@todo Consider case when to go beyond last transition (cycle //could become endless) while (tz.getStandardOffset(to) != tz.getOffset(to)) { to = tz.nextTransition(to); } while ((from <= to) && (oldFrom != from)) { transitions.add(new TimeZoneTransition(tz.getOffset(from), from, id)); oldFrom = from; from = tz.nextTransition(oldFrom); } } }