/*[deutsch]
<p>Existiert dieser Zeitstempel in der angegebenen Zeitzone? </p>

@param   tzid    timezone id (optional)
@return  {@code true} if this timestamp is valid in given timezone
@throws  IllegalArgumentException if given timezone cannot be loaded
978362
public boolean isValid(TZID tzid) {

        if (tzid == null) {
            return false;
        }

        return !Timezone.of(tzid).isInvalid(this.date, this.time);

    }
299326
@Override
    public String getExemplarLocationName(String tzID) {
        if (tzID == null || tzID.length() == 0) {
            return null;
        }
        String locName = loadTimeZoneNames(tzID).getName(NameType.EXEMPLAR_LOCATION);
        return locName;
    }
623279
public static Date fromISODateTime(final String val,
                                     final TimeZone tz) throws BadDateException {
    try {
      synchronized (isoDateTimeTZFormat) {
        isoDateTimeTZFormat.setTimeZone(tz);
        return isoDateTimeTZFormat.parse(val);
      }
    } catch (Throwable t) {
      throw new BadDateException();
    }
  }
96670
public static long timestampCeil(TimeUnitRange range, long ts, TimeZone tz) {
		// assume that we are at UTC timezone, just for algorithm performance
		long offset = tz.getOffset(ts);
		long utcTs = ts + offset;

		switch (range) {
			case HOUR:
				return ceil(utcTs, MILLIS_PER_HOUR) - offset;
			case DAY:
				return ceil(utcTs, MILLIS_PER_DAY) - offset;
			case MONTH:
			case YEAR:
			case QUARTER:
				int days = (int) (utcTs / MILLIS_PER_DAY + EPOCH_JULIAN);
				return julianDateFloor(range, days, false) * MILLIS_PER_DAY - offset;
			default:
				// for MINUTE and SECONDS etc...,
				// it is more effective to use arithmetic Method
				throw new AssertionError(range);
		}
	}
996980
def datetime_to_timezone(date, tz="UTC"):
    
    if not date.tzinfo:
        date = date.replace(tzinfo=timezone(get_timezone()))
    return date.astimezone(timezone(tz))
925529
public static Calendar getCalendar(TimeZone tz, Locale locale)
    {
        if(tz == null)
            tz = getCurrentTimeZone();
        if(locale == null)
            locale = getCurrentLocale();
        return Calendar.getInstance(tz, locale);
    }
557201
protected function isValidTimeZoneId($timeZone)
    {
        return ($this->isValidIanaTimeZoneId($timeZone) !== false || $this->isValidCldrTimeZoneId($timeZone) !== false);
    }
1225262
static public long getDateTime(String s, String format, TimeZone tz)
    {
        long ret = 0L;
        SimpleDateFormat df = null;

        try
        {
            if(s != null && s.length() > 0)
            {
                df = formatPool.getFormat(format);
                df.setTimeZone(tz);
                Date dt = df.parse(s);
                ret = dt.getTime();
            }
        }
        catch(Exception e)
        {
        }

        if(df != null)
            formatPool.release(df);

        return ret;
    }
1059326
protected String format(final String pattern, final TimeZone timeZone) {
        return format((Date) getValue(), pattern, timeZone);
    }
677236
private static String getTimeForApi (Date dt) {
        Calendar calendar = new GregorianCalendar();
        TimeZone timeZone = calendar.getTimeZone();
        Calendar cal = Calendar.getInstance(timeZone);
        cal.setTime(dt);
        return String.format("%tFT%<tRZ", cal);
    }
845728
public static PeriodValue parsePeriodValue(String s, TimeZone tzid)
            throws ParseException {
        int sep = s.indexOf('/');
        if (sep < 0) {
            throw new ParseException(s, s.length());
        }
        DateValue start = parseDateValue(s.substring(0, sep), tzid),
                end = parseDateValue(s.substring(sep + 1), tzid);
        if ((start instanceof TimeValue) != (end instanceof TimeValue)) {
            throw new ParseException(s, 0);
        }
        try {
            return PeriodValueImpl.create(start, end);
        } catch (IllegalArgumentException ex) {
            throw (ParseException) new ParseException(s, sep + 1).initCause(ex);
        }
    }
870653
@Override
    public String getTimeZoneDisplayName(String tzID, NameType type) {
        if (tzID == null || tzID.length() == 0) {
            return null;
        }
        return loadTimeZoneNames(tzID).getName(type);
    }
393604
def localize(dt, tz):
    
    if not isinstance(tz, tzinfo):
        tz = pytz.timezone(tz)

    return tz.localize(dt)
473401
protected function isValidIanaTimeZoneId($timeZone)
    {
        if (in_array($timeZone, $this->validTimeZones)) {
            return true;
        }

        $valid = array();
        $tza   = timezone_abbreviations_list();

        foreach ($tza as $zone) {
            foreach ($zone as $item) {
                $valid[$item['timezone_id']] = true;
            }
        }

        unset($valid['']);

        if (isset($valid[$timeZone]) || in_array($timeZone, timezone_identifiers_list(\DateTimeZone::ALL_WITH_BC))) {
            $this->validTimeZones[] = $timeZone;

            return true;
        }

        return false;
    }
99649
@SuppressWarnings("unused")
  public static String rfcDateTime(final Date val, final TimeZone tz) {
    synchronized (rfcDateTimeTZFormat) {
      rfcDateTimeTZFormat.setTimeZone(tz);
      return rfcDateTimeTZFormat.format(val);
    }
  }
1275034
public static ZoneId getTimeZoneId(final TimeZone tz) {
        return ZoneId.of(tz.getID(), ZoneId.SHORT_IDS);
    }
760114
@SuppressWarnings("unused")
  public static Date fromISODateTimeUTC(final String val,
                                        final TimeZone tz) throws BadDateException {
    try {
      synchronized (isoDateTimeUTCTZFormat) {
        isoDateTimeUTCTZFormat.setTimeZone(tz);
        return isoDateTimeUTCTZFormat.parse(val);
      }
    } catch (Throwable t) {
      throw new BadDateException();
    }
  }