List of usage examples for org.joda.time DateTimeZone forOffsetMillis
public static DateTimeZone forOffsetMillis(int millisOffset)
From source file:io.warp10.script.mapper.MapperMinuteOfHour.java
License:Apache License
public MapperMinuteOfHour(String name, Object timezone) { super(name);/* w ww.ja v a 2 s. co m*/ if (timezone instanceof String) { this.dtz = DateTimeZone.forID(timezone.toString()); } else if (timezone instanceof Number) { this.dtz = DateTimeZone.forOffsetMillis(((Number) timezone).intValue()); } else { this.dtz = DateTimeZone.UTC; } }
From source file:io.warp10.script.mapper.MapperMonthOfYear.java
License:Apache License
public MapperMonthOfYear(String name, Object timezone) { super(name);/* w w w .j a v a2 s . c om*/ if (timezone instanceof String) { this.dtz = DateTimeZone.forID(timezone.toString()); } else if (timezone instanceof Number) { this.dtz = DateTimeZone.forOffsetMillis(((Number) timezone).intValue()); } else { this.dtz = DateTimeZone.UTC; } }
From source file:io.warp10.script.mapper.MapperSecondOfMinute.java
License:Apache License
public MapperSecondOfMinute(String name, Object timezone) { super(name);// w w w .j ava2s . c o m if (timezone instanceof String) { this.dtz = DateTimeZone.forID(timezone.toString()); } else if (timezone instanceof Number) { this.dtz = DateTimeZone.forOffsetMillis(((Number) timezone).intValue()); } else { this.dtz = DateTimeZone.UTC; } }
From source file:io.warp10.script.mapper.MapperYear.java
License:Apache License
public MapperYear(String name, Object timezone) { super(name);/*from w w w.j a v a 2 s.c om*/ if (timezone instanceof String) { this.dtz = DateTimeZone.forID(timezone.toString()); } else if (timezone instanceof Number) { this.dtz = DateTimeZone.forOffsetMillis(((Number) timezone).intValue()); } else { this.dtz = DateTimeZone.UTC; } }
From source file:jp.furplag.util.time.DateTimeUtils.java
License:Apache License
/** * Constructs an instance from an Object that represents a datetime. * <p>//from www .ja v a 2s.c om * {@code initializer} specifiable * <ul> * <li>{@code DateTime} means {@code initializer.withMillis(new DateTime(instant).getMillis())}.</li> * <li>{@code DateTimeZone} and {@code TimeZone} means {@code new DateTime(instant, jp.furplag.util.Localizer.newDateTimeZone(initializer))}.</li> * <li>{@code String} means time zone ID or offset time ( {@code new DateTime(instant, jp.furplag.util.Localizer.newDateTimeZone(initializer))} ).</li> * <li>{@code Chronology} means {@code new DateTime(instant, initializer)}.</li> * <li>{@code long} means the milliseconds of offset to UTC ( {@code new DateTime(instant, DateTimeZone.forOffsetMillis(initializer.getMillisOfDay()))} ).</li> * <li>{@code LocalTime} means the time of offset to UTC ( {@code new DateTime(instant, DateTimeZone.forOffsetMillis(initializer.getMillisOfDay()))} ).</li> * </ul> * </p> * * @param instant the datetime object. If {@code strictly} is false, null means current date-time. * @param initializer structure for {@code instant}. * @param strictly if true, throw exceptions when the instant is invalid. And if false, returns null when the instant is invalid. * @return an instance from an Object that represents a datetime. * @throws IllegalArgumentException if the instant is invalid. */ public static DateTime toDT(final Object instant, final Object initializer, final boolean strictly) { if (strictly && instant == null) return null; if (initializer == null) return getDateTime(instant, DateTimeZone.UTC, strictly); if (initializer instanceof DateTime) return getDateTime(instant, ((DateTime) initializer), strictly); if (initializer instanceof DateTimeZone) return getDateTime(instant, ((DateTimeZone) initializer), strictly); if (initializer instanceof Chronology) return getDateTime(instant, ((Chronology) initializer), strictly); if (initializer instanceof TimeZone) return getDateTime(instant, Localizer.getDateTimeZone(initializer), strictly); if (initializer instanceof String) return getDateTime(instant, Localizer.getDateTimeZone(initializer), strictly); if (initializer instanceof LocalTime) return getDateTime(instant, DateTimeZone.forOffsetMillis(((LocalTime) initializer).getMillisOfDay()), strictly); if (Number.class.isAssignableFrom(ClassUtils.primitiveToWrapper(initializer.getClass()))) { if (NumberUtils.compareTo(valueOf(initializer), MILLIS_OF_DAY) < 0) return getDateTime(instant, DateTimeZone.forOffsetMillis(valueOf(initializer, int.class)), strictly); } return getDateTime(instant, DateTimeZone.UTC, strictly); }
From source file:name.cphillipson.experimental.gwt.server.interceptor.DateTimeZoneHandlerInterceptor.java
License:Apache License
private DateTimeZone getTimeZone(HttpServletRequest request) { final Integer millisOffset = getMillisOffset(request); if (millisOffset != null) { try {// w w w. j a va 2 s . co m return DateTimeZone.forOffsetMillis(millisOffset); } catch (final IllegalArgumentException e) { return DateTimeZone.getDefault(); } } else { return DateTimeZone.getDefault(); } }
From source file:net.naonedbus.provider.impl.FastDateTimeZoneProvider.java
License:Open Source License
public DateTimeZone getZone(String id) { if (id == null) { return DateTimeZone.UTC; }// www .j a v a 2s. c om TimeZone tz = TimeZone.getTimeZone(id); if (tz == null) { return DateTimeZone.UTC; } int rawOffset = tz.getRawOffset(); // sub-optimal. could be improved to only create a new Date every few // minutes if (tz.inDaylightTime(new Date())) { rawOffset += tz.getDSTSavings(); } return DateTimeZone.forOffsetMillis(rawOffset); }
From source file:nz.al4.airclock.TimeCalculator.java
License:Open Source License
/** * Calculate when to set an alarm given a LocalDateTime (no time zone information) * * To do this, we need to figure out what time zone will be applied when we hit this time... * far from trivial!/*from w w w .java2s .co m*/ * * So we use linear algebra to create simple formulas for the absolute time and tz offet of our * alarm. * * @param localAlarmTime * @return */ public DateTime timeForAlarm(LocalDateTime localAlarmTime) { Log.d("timeForAlarm", "Calculating alarm for time " + localAlarmTime.toString()); // x axis, Time in ms since 1970 long To = mOriginTime.getMillis(); // x1 long Td = mDestTime.getMillis(); // x3 // y axis, Offset in milliseconds long Oo = mOriginTime.getZone().getOffset(mOriginTime); // y1 long Od = mDestTime.getZone().getOffset(mDestTime); // y3 System.out.println(String.valueOf(To) + ',' + String.valueOf(Oo)); System.out.println(String.valueOf(Td) + ',' + String.valueOf(Od)); // slope = x/y float slope = (Td - To) / (Od - Oo); Log.v("debug", String.valueOf(slope)); System.out.println(String.valueOf(slope)); /* now that we have the slope, we can use algebra to rearrange what we know and come up with formulas for what we don't. * (x1, y1) is the point at takeoff, i.e (To, Oo) * our unknown point, the alarm point is (x2, y2) => (Ta, Oa) (Time of alarm, offset of alarm) * the localtime of the alarm we want to calculate, T, equals x2 (absolute time at alarm) plus y2 (offset at time of alarm) (tz offset at alarm time), i.e T=x2+y2 by rearranging the slope formula, y2 = (x2 - x1)/S + y1 therefore T - x2 = (x2 - x1)/S + y1 etc, until we get the formulas below */ // UTC is zero offset, long T = localAlarmTime.toDateTime(DateTimeZone.UTC).getMillis(); System.out.println("T " + String.valueOf(T)); double Ta = ((slope * To) - Oo + T) / (slope + 1); System.out.println("Ta " + String.valueOf(Ta)); // y2 = T - x2 double Oa = T - Ta; System.out.println("Oa " + String.valueOf(Oa)); // construct a datetime DateTimeZone alarmTz = DateTimeZone.forOffsetMillis((int) Oa); DateTime alarmTime = new DateTime((long) Ta, alarmTz); Log.d("timeForAlarm", "as origin: " + alarmTime.toDateTime(mOriginTime.getZone()).toString()); Log.d("timeForAlarm", "as dest: " + alarmTime.toDateTime(mDestTime.getZone()).toString()); return alarmTime; }
From source file:org.apache.isis.objectstore.sql.jdbc.JdbcConnector.java
License:Apache License
private void addPreparedValues(final PreparedStatement statement) throws SQLException { if (queryValues.size() > 0) { int i = 1; try {/*from ww w. ja v a2 s .c o m*/ for (final Object value : queryValues) { if (value instanceof LocalDate) { try { statement.setObject(i, value, java.sql.Types.DATE); } catch (final SQLException e) { // TODO This daft catch is required my MySQL, which // also requires the TimeZone offset to be // "undone" final LocalDate localDate = (LocalDate) value; final int millisOffset = -DateTimeZone.getDefault().getOffset(null); final java.util.Date javaDate = localDate .toDateTimeAtStartOfDay(DateTimeZone.forOffsetMillis(millisOffset)).toDate(); statement.setObject(i, javaDate, java.sql.Types.DATE); } } else if (value instanceof InputStream) { statement.setBlob(i, (InputStream) value); } else { statement.setObject(i, value); } i++; } } catch (final SQLException e) { LOG.error("Error adding prepared value " + i + " of type " + queryValues.get(i - 1).getClass().getSimpleName(), e); throw e; } } }
From source file:org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.JdbcConnector.java
License:Apache License
private void addPreparedValues(final PreparedStatement statement) throws SQLException { if (queryValues.size() > 0) { int i = 1; try {//from w w w .ja va2s .co m for (final Object value : queryValues) { if (value instanceof LocalDate) { try { statement.setObject(i, value, java.sql.Types.DATE); } catch (final SQLException e) { // TODO This daft catch is required my MySQL, which // also requires the TimeZone offset to be // "undone" final LocalDate localDate = (LocalDate) value; final int millisOffset = -DateTimeZone.getDefault().getOffset(null); final java.util.Date javaDate = localDate .toDateTimeAtStartOfDay(DateTimeZone.forOffsetMillis(millisOffset)).toDate(); statement.setObject(i, javaDate, java.sql.Types.DATE); } } else { statement.setObject(i, value); } i++; } } catch (final SQLException e) { LOG.error("Error adding prepared value " + i + " of type " + queryValues.get(i - 1).getClass().getSimpleName(), e); throw e; } } }