/** * <p>Adjusts a Calendar's value to a different TimeZone.</p> * * @param value The value to adjust. * @param timeZone The new time zone to use to adjust the Calendar to. */ public static void adjustToTimeZone(Calendar value, TimeZone timeZone) { if (value.getTimeZone().hasSameRules(timeZone)) { value.setTimeZone(timeZone); } else { int year = value.get(Calendar.YEAR); int month = value.get(Calendar.MONTH); int date = value.get(Calendar.DATE); int hour = value.get(Calendar.HOUR_OF_DAY); int minute = value.get(Calendar.MINUTE); value.setTimeZone(timeZone); value.set(year, month, date, hour, minute); } }
assertTrue("SAME: UTC = GMT", UTC.hasSameRules(GMT)); assertEquals("SAME: Check time (A)", calUTC.getTime(), calGMT.getTime()); assertFalse("SAME: Check GMT(A)", GMT.equals(calUTC.getTimeZone()));
/** * Returns true if this zone has the same rule and offset as another zone. * That is, if this zone differs only in ID, if at all. Returns false * if the other zone is null. * @param other the <code>TimeZone</code> object to be compared with * @return true if the other zone is not null and is the same as this one, * with the possible exception of the ID * @stable ICU 2.0 */ public boolean hasSameRules(TimeZone other) { return timeZone.hasSameRules(other.timeZone); }
/** * Returns true if this zone has the same rule and offset as another zone. * That is, if this zone differs only in ID, if at all. Returns false * if the other zone is null. * @param other the <code>TimeZone</code> object to be compared with * @return true if the other zone is not null and is the same as this one, * with the possible exception of the ID * @stable ICU 2.0 */ public boolean hasSameRules(TimeZone other) { return timeZone.hasSameRules(other.timeZone); }
private static void adjustCalendarForTime( Calendar initial, Calendar target ) { assert initial != null; if (initial.getTimeZone().hasSameRules(target.getTimeZone())) { target.setTime(initial.getTime()); return; } target.clear(); for (int i = 0; i <= Calendar.MILLISECOND; i++) { target.set(i, initial.get(i)); } }
private static void adjustCalendarForTime( Calendar initial, Calendar target ) { assert initial != null; if (initial.getTimeZone().hasSameRules(target.getTimeZone())) { target.setTime(initial.getTime()); return; } target.clear(); for (int i = 0; i <= Calendar.MILLISECOND; i++) { target.set(i, initial.get(i)); } }
private static Calendar adjustCalendarForDate( Calendar initial, Calendar target ) { assert initial != null; if (initial.getTimeZone().hasSameRules(target.getTimeZone())) { target.setTime(initial.getTime()); return target; } Calendar ntarget = new GregorianCalendar(target.getTimeZone()); ntarget.setTimeInMillis(initial.getTimeInMillis()); return ntarget; }
private static Calendar adjustCalendarForDate( Calendar initial, Calendar target ) { assert initial != null; if (initial.getTimeZone().hasSameRules(target.getTimeZone())) { target.setTime(initial.getTime()); return target; } Calendar ntarget = new GregorianCalendar(target.getTimeZone()); ntarget.setTimeInMillis(initial.getTimeInMillis()); return ntarget; }
private void init(Calendar calendar) { TimeZone tz = calendar.getTimeZone(); if (!(tz.hasSameRules(TimeZoneUtil.DefaultTZ) || tz.hasSameRules(TimeZoneUtil.UTC))) { tz = TimeZoneUtil.UTC; Calendar c = (Calendar) calendar.clone(); c.setTimeZone(tz); calendar = c; } this.year = calendar.get(Calendar.YEAR); this.month = calendar.get(Calendar.MONTH) + 1; this.day = calendar.get(Calendar.DAY_OF_MONTH); this.hour = calendar.get(Calendar.HOUR_OF_DAY); this.minute = calendar.get(Calendar.MINUTE); this.second = calendar.get(Calendar.SECOND); this.nanosecond = calendar.get(Calendar.MILLISECOND) * 1000000; this.utc = tz.hasSameRules(TimeZoneUtil.UTC); }
@Override protected Calendar initialValue() { if(this.timeZone != null && this.timeZone.trim().length() > 0) { TimeZone tz = TimeZone.getTimeZone(this.timeZone); if(!TimestampWithTimezone.getCalendar().getTimeZone().hasSameRules(tz)) { return Calendar.getInstance(tz); } } return Calendar.getInstance(); } };
@Override public void start() throws TranslatorException { super.start(); if(this.databaseTimeZone != null && this.databaseTimeZone.trim().length() > 0) { TimeZone tz = TimeZone.getTimeZone(this.databaseTimeZone); if(!DEFAULT_TIME_ZONE.hasSameRules(tz)) { this.timeZone = tz;; } } }
@Override public boolean hasSameRules(java.util.TimeZone other) { return other.hasSameRules(TimeZoneICU.wrap(fIcuTz)); }
private static Calendar adjustCalendarForTimeStamp( Calendar initial, Calendar target ) { assert initial != null; if (initial.getTimeZone().hasSameRules(target.getTimeZone())) { target.setTime(initial.getTime()); return target; } TimeZone targetTimeZone = target.getTimeZone(); Calendar ret = new GregorianCalendar(targetTimeZone); ret.setTimeInMillis(initial.getTimeInMillis() + targetTimeZone.getOffset(initial.getTimeInMillis()) - initial.getTimeZone().getOffset(initial.getTimeInMillis())); ret.getTime(); return ret; } }
private static Calendar adjustCalendarForTimeStamp( Calendar initial, Calendar target ) { assert initial != null; if (initial.getTimeZone().hasSameRules(target.getTimeZone())) { target.setTime(initial.getTime()); return target; } TimeZone targetTimeZone = target.getTimeZone(); Calendar ret = new GregorianCalendar(targetTimeZone); ret.setTimeInMillis(initial.getTimeInMillis() + targetTimeZone.getOffset(initial.getTimeInMillis()) - initial.getTimeZone().getOffset(initial.getTimeInMillis())); ret.getTime(); return ret; } }
@Override public final void serialize(Writer writer, Calendar calendar) throws IOException { super.serialize(writer, calendar); TimeZone tz = calendar.getTimeZone(); if (!(tz.hasSameRules(TimeZoneUtil.DefaultTZ) || tz.hasSameRules(TimeZoneUtil.UTC))) { tz = TimeZoneUtil.UTC; Calendar c = (Calendar) calendar.clone(); c.setTimeZone(tz); calendar = c; } OutputStream stream = writer.stream; ValueWriter.writeDateOfCalendar(stream, calendar); ValueWriter.writeTimeOfCalendar(stream, calendar, true, false); stream.write(tz.hasSameRules(TimeZoneUtil.UTC) ? TagUTC : TagSemicolon); } }
@Override public final void serialize(Writer writer, Calendar calendar) throws IOException { super.serialize(writer, calendar); TimeZone tz = calendar.getTimeZone(); if (!(tz.hasSameRules(TimeZoneUtil.DefaultTZ) || tz.hasSameRules(TimeZoneUtil.UTC))) { tz = TimeZoneUtil.UTC; Calendar c = (Calendar) calendar.clone(); c.setTimeZone(tz); calendar = c; } OutputStream stream = writer.stream; ValueWriter.writeDateOfCalendar(stream, calendar); ValueWriter.writeTimeOfCalendar(stream, calendar, true, false); stream.write(tz.hasSameRules(TimeZoneUtil.UTC) ? HproseTags.TagUTC : HproseTags.TagSemicolon); } }
@Override public final void serialize(Writer writer, Calendar calendar) throws IOException { super.serialize(writer, calendar); TimeZone tz = calendar.getTimeZone(); if (!(tz.hasSameRules(TimeZoneUtil.DefaultTZ) || tz.hasSameRules(TimeZoneUtil.UTC))) { tz = TimeZoneUtil.UTC; Calendar c = (Calendar) calendar.clone(); c.setTimeZone(tz); calendar = c; } OutputStream stream = writer.stream; ValueWriter.writeDateOfCalendar(stream, calendar); ValueWriter.writeTimeOfCalendar(stream, calendar, true, false); stream.write(tz.hasSameRules(TimeZoneUtil.UTC) ? TagUTC : TagSemicolon); } }
Date getDateValueFromString(String attributeValue) { Date parsedDateValue = parseDateValue(attributeValue); TimeZone siteTimeZone = reviewboardClientData.getTimeZone(); if ( parsedDateValue == null || siteTimeZone == null || targetTimeZone.hasSameRules(siteTimeZone)) return parsedDateValue; long localOffset = this.targetTimeZone.getOffset(parsedDateValue.getTime()); long siteOffset = siteTimeZone.getOffset(parsedDateValue.getTime()); return new Date(parsedDateValue.getTime() + ( localOffset - siteOffset )); }
TimeZone customTimeZone = TimeZone.getTimeZone("GMT-07:00"); TimeZone officialTimeZone = null; for (String timeZoneId : TimeZone.getAvailableIDs()) { if (TimeZone.getTimeZone(timeZoneId).hasSameRules(customTimeZone)){ officialTimeZone = TimeZone.getTimeZone(timeZoneId); break; } } ZoneRules zoneRules = ZoneRulesProvider.getRules(officialTimeZone.toZoneId().getId(), true); System.out.println(zoneRules);
/** * <p>MMPreparedStatement constructor. * @param Driver's connection object. * @param String object representing the prepared statement */ PreparedStatementImpl(ConnectionImpl connection, String sql, int resultSetType, int resultSetConcurrency) throws SQLException { super(connection, resultSetType, resultSetConcurrency); if (sql == null) { throw new TeiidSQLException(JDBCPlugin.Util.getString("MMPreparedStatement.Err_prep_sql")); //$NON-NLS-1$ } this.prepareSql = sql; TimeZone timezone = connection.getServerConnection().getLogonResult().getTimeZone(); if (timezone != null && !timezone.hasSameRules(getDefaultCalendar().getTimeZone())) { this.serverCalendar = Calendar.getInstance(timezone); } }