Java Code Examples for java.util.TimeZone#useDaylightTime()

The following examples show how to use java.util.TimeZone#useDaylightTime() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZoneInfoOld.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns true if this zone has the same raw GMT offset value and
 * transition table as another zone info. If the specified
 * TimeZone object is not a ZoneInfoOld instance, this method returns
 * true if the specified TimeZone object has the same raw GMT
 * offset value with no daylight saving time.
 *
 * @param other the ZoneInfoOld object to be compared with
 * @return true if the given <code>TimeZone</code> has the same
 * GMT offset and transition information; false, otherwise.
 */
public boolean hasSameRules(TimeZone other) {
    if (this == other) {
        return true;
    }
    if (other == null) {
        return false;
    }
    if (!(other instanceof ZoneInfoOld)) {
        if (getRawOffset() != other.getRawOffset()) {
            return false;
        }
        // if both have the same raw offset and neither observes
        // DST, they have the same rule.
        if ((transitions == null)
            && (useDaylightTime() == false)
            && (other.useDaylightTime() == false)) {
            return true;
        }
        return false;
    }
    if (getLastRawOffset() != ((ZoneInfoOld)other).getLastRawOffset()) {
        return false;
    }
    return (checksum == ((ZoneInfoOld)other).checksum);
}
 
Example 2
Source File: Arja_0097_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void appendTo(StringBuffer buffer, Calendar calendar) {
    if (mTimeZoneForced) {
        if (mTimeZone.useDaylightTime() && calendar.get(Calendar.DST_OFFSET) != 0) {
            buffer.append(mDaylight);
        } else {
            buffer.append(mStandard);
        }
    } else {
        TimeZone timeZone = calendar.getTimeZone();
        if (timeZone.useDaylightTime() && calendar.get(Calendar.DST_OFFSET) != 0) {
            buffer.append(getTimeZoneDisplay(timeZone, true, mStyle, mLocale));
        } else {
            buffer.append(getTimeZoneDisplay(timeZone, false, mStyle, mLocale));
        }
    }
}
 
Example 3
Source File: ZoneInfoOld.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns true if this zone has the same raw GMT offset value and
 * transition table as another zone info. If the specified
 * TimeZone object is not a ZoneInfoOld instance, this method returns
 * true if the specified TimeZone object has the same raw GMT
 * offset value with no daylight saving time.
 *
 * @param other the ZoneInfoOld object to be compared with
 * @return true if the given <code>TimeZone</code> has the same
 * GMT offset and transition information; false, otherwise.
 */
public boolean hasSameRules(TimeZone other) {
    if (this == other) {
        return true;
    }
    if (other == null) {
        return false;
    }
    if (!(other instanceof ZoneInfoOld)) {
        if (getRawOffset() != other.getRawOffset()) {
            return false;
        }
        // if both have the same raw offset and neither observes
        // DST, they have the same rule.
        if ((transitions == null)
            && (useDaylightTime() == false)
            && (other.useDaylightTime() == false)) {
            return true;
        }
        return false;
    }
    if (getLastRawOffset() != ((ZoneInfoOld)other).getLastRawOffset()) {
        return false;
    }
    return (checksum == ((ZoneInfoOld)other).checksum);
}
 
Example 4
Source File: ZoneInfo.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns true if this zone has the same raw GMT offset value and
 * transition table as another zone info. If the specified
 * TimeZone object is not a ZoneInfo instance, this method returns
 * true if the specified TimeZone object has the same raw GMT
 * offset value with no daylight saving time.
 *
 * @param other the ZoneInfo object to be compared with
 * @return true if the given <code>TimeZone</code> has the same
 * GMT offset and transition information; false, otherwise.
 */
public boolean hasSameRules(TimeZone other) {
    if (this == other) {
        return true;
    }
    if (other == null) {
        return false;
    }
    if (!(other instanceof ZoneInfo)) {
        if (getRawOffset() != other.getRawOffset()) {
            return false;
        }
        // if both have the same raw offset and neither observes
        // DST, they have the same rule.
        if ((transitions == null)
            && (useDaylightTime() == false)
            && (other.useDaylightTime() == false)) {
            return true;
        }
        return false;
    }
    if (getLastRawOffset() != ((ZoneInfo)other).getLastRawOffset()) {
        return false;
    }
    return (checksum == ((ZoneInfo)other).checksum);
}
 
Example 5
Source File: 1_FastDateFormat.java    From SimFix with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void appendTo(StringBuffer buffer, Calendar calendar) {
    if (mTimeZoneForced) {
        if (mTimeZone.useDaylightTime() && calendar.get(Calendar.DST_OFFSET) != 0) {
            buffer.append(mDaylight);
        } else {
            buffer.append(mStandard);
        }
    } else {
        TimeZone timeZone = calendar.getTimeZone();
        if (timeZone.useDaylightTime() && calendar.get(Calendar.DST_OFFSET) != 0) {
            buffer.append(getTimeZoneDisplay(timeZone, true, mStyle, mLocale));
        } else {
            buffer.append(getTimeZoneDisplay(timeZone, false, mStyle, mLocale));
        }
    }
}
 
Example 6
Source File: Arja_0019_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void appendTo(StringBuffer buffer, Calendar calendar) {
    if (mTimeZoneForced) {
        if (mTimeZone.useDaylightTime() && calendar.get(Calendar.DST_OFFSET) != 0) {
            buffer.append(mDaylight);
        } else {
            buffer.append(mStandard);
        }
    } else {
        TimeZone timeZone = calendar.getTimeZone();
        if (timeZone.useDaylightTime() && calendar.get(Calendar.DST_OFFSET) != 0) {
            buffer.append(getTimeZoneDisplay(timeZone, true, mStyle, mLocale));
        } else {
            buffer.append(getTimeZoneDisplay(timeZone, false, mStyle, mLocale));
        }
    }
}
 
Example 7
Source File: FastDateFormat.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void appendTo(StringBuffer buffer, Calendar calendar) {
    if (mTimeZoneForced) {
        if (mTimeZone.useDaylightTime() && calendar.get(Calendar.DST_OFFSET) != 0) {
            buffer.append(mDaylight);
        } else {
            buffer.append(mStandard);
        }
    } else {
        TimeZone timeZone = calendar.getTimeZone();
        if (timeZone.useDaylightTime() && calendar.get(Calendar.DST_OFFSET) != 0) {
            buffer.append(getTimeZoneDisplay(timeZone, true, mStyle, mLocale));
        } else {
            buffer.append(getTimeZoneDisplay(timeZone, false, mStyle, mLocale));
        }
    }
}
 
Example 8
Source File: ZoneInfo.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns true if this zone has the same raw GMT offset value and
 * transition table as another zone info. If the specified
 * TimeZone object is not a ZoneInfo instance, this method returns
 * true if the specified TimeZone object has the same raw GMT
 * offset value with no daylight saving time.
 *
 * @param other the ZoneInfo object to be compared with
 * @return true if the given <code>TimeZone</code> has the same
 * GMT offset and transition information; false, otherwise.
 */
public boolean hasSameRules(TimeZone other) {
    if (this == other) {
        return true;
    }
    if (other == null) {
        return false;
    }
    if (!(other instanceof ZoneInfo)) {
        if (getRawOffset() != other.getRawOffset()) {
            return false;
        }
        // if both have the same raw offset and neither observes
        // DST, they have the same rule.
        if ((transitions == null)
            && (useDaylightTime() == false)
            && (other.useDaylightTime() == false)) {
            return true;
        }
        return false;
    }
    if (getLastRawOffset() != ((ZoneInfo)other).getLastRawOffset()) {
        return false;
    }
    return (checksum == ((ZoneInfo)other).checksum);
}
 
Example 9
Source File: FastDateFormat.java    From gflogger with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void appendTo(CharBuffer buffer, Calendar calendar) {
	if (mTimeZoneForced) {
		if (mTimeZone.useDaylightTime() && calendar.get(Calendar.DST_OFFSET) != 0) {
			buffer.append(mDaylight);
		} else {
			buffer.append(mStandard);
		}
	} else {
		TimeZone timeZone = calendar.getTimeZone();
		if (timeZone.useDaylightTime() && calendar.get(Calendar.DST_OFFSET) != 0) {
			buffer.append(getTimeZoneDisplay(timeZone, true, mStyle, mLocale));
		} else {
			buffer.append(getTimeZoneDisplay(timeZone, false, mStyle, mLocale));
		}
	}
}
 
Example 10
Source File: 1_FastDateFormat.java    From SimFix with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void appendTo(StringBuffer buffer, Calendar calendar) {
    if (mTimeZoneForced) {
        if (mTimeZone.useDaylightTime() && calendar.get(Calendar.DST_OFFSET) != 0) {
            buffer.append(mDaylight);
        } else {
            buffer.append(mStandard);
        }
    } else {
        TimeZone timeZone = calendar.getTimeZone();
        if (timeZone.useDaylightTime() && calendar.get(Calendar.DST_OFFSET) != 0) {
            buffer.append(getTimeZoneDisplay(timeZone, true, mStyle, mLocale));
        } else {
            buffer.append(getTimeZoneDisplay(timeZone, false, mStyle, mLocale));
        }
    }
}
 
Example 11
Source File: DERGeneralizedTime.java    From TorrentEngine with GNU General Public License v3.0 5 votes vote down vote up
private String calculateGMTOffset()
{
    String sign = "+";
    TimeZone timeZone = TimeZone.getDefault();
    int offset = timeZone.getRawOffset();
    if (offset < 0)
    {
        sign = "-";
        offset = -offset;
    }
    int hours = offset / (60 * 60 * 1000);
    int minutes = (offset - (hours * 60 * 60 * 1000)) / (60 * 1000);

    try
    {
        if (timeZone.useDaylightTime() && timeZone.inDaylightTime(this.getDate()))
        {
            hours += sign.equals("+") ? 1 : -1;
        }
    }
    catch (ParseException e)
    {
        // we'll do our best and ignore daylight savings
    }

    return "GMT" + sign + convert(hours) + ":" + convert(minutes);
}
 
Example 12
Source File: DERGeneralizedTime.java    From BiglyBT with GNU General Public License v2.0 5 votes vote down vote up
private String calculateGMTOffset()
{
    String sign = "+";
    TimeZone timeZone = TimeZone.getDefault();
    int offset = timeZone.getRawOffset();
    if (offset < 0)
    {
        sign = "-";
        offset = -offset;
    }
    int hours = offset / (60 * 60 * 1000);
    int minutes = (offset - (hours * 60 * 60 * 1000)) / (60 * 1000);

    try
    {
        if (timeZone.useDaylightTime() && timeZone.inDaylightTime(this.getDate()))
        {
            hours += sign.equals("+") ? 1 : -1;
        }
    }
    catch (ParseException e)
    {
        // we'll do our best and ignore daylight savings
    }

    return "GMT" + sign + convert(hours) + ":" + convert(minutes);
}
 
Example 13
Source File: FastDatePrinter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void appendTo(StringBuffer buffer, Calendar calendar) {
    TimeZone zone = calendar.getTimeZone();
    if (zone.useDaylightTime()
            && calendar.get(Calendar.DST_OFFSET) != 0) {
        buffer.append(getTimeZoneDisplay(zone, true, mStyle, mLocale));
    } else {
        buffer.append(getTimeZoneDisplay(zone, false, mStyle, mLocale));
    }
}
 
Example 14
Source File: FastDatePrinter.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void appendTo(final StringBuffer buffer, final Calendar calendar) {
    final TimeZone zone = calendar.getTimeZone();
    if (zone.useDaylightTime()
            && calendar.get(Calendar.DST_OFFSET) != 0) {
        buffer.append(getTimeZoneDisplay(zone, true, mStyle, mLocale));
    } else {
        buffer.append(getTimeZoneDisplay(zone, false, mStyle, mLocale));
    }
}
 
Example 15
Source File: FastDatePrinter.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void appendTo(final StringBuffer buffer, final Calendar calendar) {
    final TimeZone zone = calendar.getTimeZone();
    if (zone.useDaylightTime()
            && calendar.get(Calendar.DST_OFFSET) != 0) {
        buffer.append(getTimeZoneDisplay(zone, true, mStyle, mLocale));
    } else {
        buffer.append(getTimeZoneDisplay(zone, false, mStyle, mLocale));
    }
}
 
Example 16
Source File: FastDatePrinter.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void appendTo(final StringBuffer buffer, final Calendar calendar) {
    final TimeZone zone = calendar.getTimeZone();
    if (zone.useDaylightTime()
            && calendar.get(Calendar.DST_OFFSET) != 0) {
        buffer.append(getTimeZoneDisplay(zone, true, mStyle, mLocale));
    } else {
        buffer.append(getTimeZoneDisplay(zone, false, mStyle, mLocale));
    }
}
 
Example 17
Source File: InnardsConverter.java    From domino-jna with Apache License 2.0 4 votes vote down vote up
/**
 * Method to convert a {@link Calendar} object to an innard array. This implementation
 * uses pure Java functions for the conversion, which is faster than using JNA.
 * 
 * @param cal calendar
 * @param hasDate true to create an innard with a date part
 * @param hasTime true to create an innard with a time part
 * @return innard array
 */
public static int[] encodeInnards(Calendar cal, boolean hasDate, boolean hasTime) {
	if (!hasDate && !hasTime) {
		return new int[] {NotesConstants.ALLDAY, NotesConstants.ANYDAY};
	}
	
	int[] innards = new int[2];

	//The first DWORD, Innards[0], contains the number of hundredths of seconds since midnight,
	if (hasTime) {
		if (hasDate) {
			long dtTimeMillisSince1970 = cal.getTimeInMillis();
			long dtTimeDaysSince1970 = dtTimeMillisSince1970 / (24*60*60*1000);
			long dtTimeMillisSince1970StartOfDay = dtTimeDaysSince1970 * 24*60*60*1000;
			
			innards[0] = (int) (((dtTimeMillisSince1970-dtTimeMillisSince1970StartOfDay) / 10) & 0xffffffff);
		}
		else {
			int hour = cal.get(Calendar.HOUR_OF_DAY);
			int minute = cal.get(Calendar.MINUTE);
			int second = cal.get(Calendar.SECOND);
			int millis = cal.get(Calendar.MILLISECOND);
			int hundredth = millis / 10;
			innards[0] = ((hour*60*60*100 + minute*60*100 + second*100 + hundredth)) & 0xffffffff;
		}
	}
	else {
		innards[0] = NotesConstants.ALLDAY;
		
		Calendar calUTC = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
		calUTC.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
		cal = calUTC;
	}

	if (!hasDate) {
		innards[1] = NotesConstants.ANYDAY;
		return innards;
	}
	
	//The 24 low-order bits contain the Julian Day, the number of days since January 1, 4713 BC
	Date dtTime = cal.getTime();
	long julianDay = toJulianDay(dtTime);

	long zoneMask = 0;
	
	TimeZone tz = cal.getTimeZone();

	//The high-order bit, bit 31 (0x80000000), is set if Daylight Savings Time is observed
	if (tz.useDaylightTime()) {
		zoneMask |= 1l << 31;
	}
	
	//Bit 30 (0x40000000) is set if the time zone is east of Greenwich mean time.
	int tzOffsetSeconds = (int)(tz.getRawOffset() / 1000);
	
	if (tzOffsetSeconds>0) {
		zoneMask |= 1l << 30;
	}
	
	int tzOffsetHours = Math.abs(tzOffsetSeconds / (60*60));
	
	
	//Bits 27-24 contain the number of hours difference between the time zone and Greenwich mean time
	zoneMask |= ((long)tzOffsetHours) << 24;

	//bits 29-28 contain the number of 15-minute intervals in the difference
	
	int tzOffsetFractionSeconds = tzOffsetSeconds - tzOffsetHours*60*60; //  tzOffset % 60;
	int tzOffsetFractionMinutes = tzOffsetFractionSeconds % 60;
	int tzOffsetFraction15MinuteIntervalls = tzOffsetFractionMinutes / 15;
	zoneMask |= ((long)tzOffsetFraction15MinuteIntervalls) << 28;

	long resultLong = julianDay | zoneMask;
	
	innards[1] = (int) (resultLong & 0xffffffff);
	
	return innards;
}
 
Example 18
Source File: InnardsConverter.java    From domino-jna with Apache License 2.0 4 votes vote down vote up
/**
 * Method to convert a {@link Calendar} object to an innard array. This implementation
 * uses the C API.
 * 
 * @param cal calendar
 * @param hasDate true to create an innard with a date part
 * @param hasTime true to create an innard with a time part
 * @return innard array
 */
public static int[] encodeInnardsWithCAPI(Calendar cal, boolean hasDate, boolean hasTime) {
	DisposableMemory m = new DisposableMemory(NotesConstants.timeSize);
	NotesTimeStruct time = NotesTimeStruct.newInstance(m);

	boolean isNZDTConversionNeeded = false;
	
	if (!hasDate) {
		//for time only items, use local time, since there is no timezone information to tell Domino we're using UTC
		
		Calendar calNow = Calendar.getInstance();
		
		time.dst=0;
		time.zone=0;

		time.hour = cal.get(Calendar.HOUR_OF_DAY);
		time.minute = cal.get(Calendar.MINUTE);
		time.second = cal.get(Calendar.SECOND);
		time.hundredth = (int) ((cal.get(Calendar.MILLISECOND) / 10) & 0xffffffff);
		
		time.day = calNow.get(Calendar.DAY_OF_MONTH);
		time.month = calNow.get(Calendar.MONTH)+1;
		time.year = calNow.get(Calendar.YEAR);
	}
	else {
		TimeZone tz = cal.getTimeZone();
		int tzRawOffset = tz.getRawOffset();
		int tzOffsetHours = (int)(tzRawOffset / 3600000);
		
		time.hour = cal.get(Calendar.HOUR_OF_DAY);
		time.minute = cal.get(Calendar.MINUTE);
		time.second = cal.get(Calendar.SECOND);
		time.hundredth = (int) ((cal.get(Calendar.MILLISECOND) / 10) & 0xffffffff);


		time.dst=tz.useDaylightTime() ? 1 : 0;
		
		//valid values for time.zone: -11 - +11
		if (tzOffsetHours == 12) {
			//special case for e.g. NZDT (New Zealand) which is UTC+13, raw offset 12 hours; switch to -11 and add one day
			isNZDTConversionNeeded = true;
			
			time.zone = 11;
			
			Calendar calNextDay = (Calendar) cal.clone();
			calNextDay.add(Calendar.DAY_OF_MONTH, -1);
			
			time.day = calNextDay.get(Calendar.DAY_OF_MONTH);
			time.month = calNextDay.get(Calendar.MONTH)+1;
			time.year = calNextDay.get(Calendar.YEAR);
		}
		else {
			time.zone=-1*tzOffsetHours;
			
			time.day = cal.get(Calendar.DAY_OF_MONTH);
			time.month = cal.get(Calendar.MONTH)+1;
			time.year = cal.get(Calendar.YEAR);
		}
	}

	time.write();

	//convert day, month, year etc. to GM NotesTimeDate
	boolean convRet = NotesNativeAPI.get().TimeLocalToGM(m);
	if (convRet) {
		String msg = "Error converting calendar value to GM: "+cal.getTime();
		throw new NotesError(0, msg);
	}
	time.read();

	int[] innards = time.GM.Innards.clone();
	m.dispose();

	if (isNZDTConversionNeeded) {
		//overwrite the wrong timezone info with the New Zealand timeout offset
		
		//Bit 30 (0x40000000) is set if the time zone is east of Greenwich mean time.
		innards[1] |= 0x40000000;
		
		//Bits 27-24 contain the number of hours difference between the time zone and Greenwich mean time
		innards[1] &= ~0xF000000;
		innards[1] |= ((long)12) << 24;
	}
	
	if (!hasDate) {
		innards[1] = NotesConstants.ANYDAY;
	}
	if (!hasTime) {
		innards[0] = NotesConstants.ALLDAY;
	}
	return innards;
}
 
Example 19
Source File: Bug6772689.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    TimeZone defaultTimeZone = TimeZone.getDefault();
    int errors = 0;

    Calendar cal = new GregorianCalendar(BEGIN_YEAR, MARCH, 1);
    String[] tzids = TimeZone.getAvailableIDs();
    try {
        for (String id : tzids) {
            TimeZone tz = TimeZone.getTimeZone(id);
            if (!tz.useDaylightTime()) {
                continue;
            }
            TimeZone.setDefault(tz);

          dateloop:
            // Use future dates because sun.util.calendar.ZoneInfo
            // delegates offset transition calculations to a SimpleTimeZone
            // (after 2038 as of JDK7).
            for (int year = BEGIN_YEAR; year < END_YEAR; year++) {
                for (int month = MARCH; month <= NOVEMBER; month++) {
                    cal.set(year, month, 1, 15, 0, 0);
                    int maxDom = cal.getActualMaximum(DAY_OF_MONTH);
                    for (int dom = 1; dom <= maxDom; dom++) {
                        Date date = new Date(year - 1900, month, dom);
                        if (date.getYear()+1900 != year
                            || date.getMonth() != month
                            || date.getDate() != dom) {
                            System.err.printf("%s: got %04d-%02d-%02d, expected %04d-%02d-%02d%n",
                                              id,
                                              date.getYear() + 1900,
                                              date.getMonth() + 1,
                                              date.getDate(),
                                              year,
                                              month + 1,
                                              dom);
                            errors++;
                            break dateloop;
                        }
                    }
                }
            }
        }
    } finally {
        // Restore the default TimeZone.
        TimeZone.setDefault(defaultTimeZone);
    }
    if (errors > 0) {
        throw new RuntimeException("Transition test failed");
    }
}
 
Example 20
Source File: TriggerUtils.java    From AsuraFramework with Apache License 2.0 3 votes vote down vote up
/**
 * <p>
 * Equivalent of TimeZone.getDSTSavings() in JDK 1.4, but Quartz is trying
 * to support JDK 1.3.
 * </p>
 * 
 * @param tz the target time-zone
 * @return the amount of saving time in milliseconds
 * @deprecated use TimeZone.getDSTSavings()
 */
public static int getDSTSavings(TimeZone tz) {
    
    if (tz.useDaylightTime()) {
        return 3600000;
    }
    return 0;
}