Constructs a timestamp from UTC fields adjusted to the local offset if given.
435905
def adjust_from_utc_fields(*args, **kwargs):
        """"""
        raw_ts = Timestamp(*args, **kwargs)
        offset = raw_ts.utcoffset()
        if offset is None or offset == timedelta():
            return raw_ts

        # XXX This returns a datetime, not a Timestamp (which has our precision if defined)
        adjusted = raw_ts + offset
        if raw_ts.precision is None:
            # No precision means we can just return a regular datetime
            return adjusted

        return Timestamp(
            adjusted.year,
            adjusted.month,
            adjusted.day,
            adjusted.hour,
            adjusted.minute,
            adjusted.second,
            adjusted.microsecond,
            raw_ts.tzinfo,
            precision=raw_ts.precision,
            fractional_precision=raw_ts.fractional_precision
        )
9202
def _timestamp_instants_eq(a, b):
    """"""
    assert isinstance(a, datetime)
    if not isinstance(b, datetime):
        return False
    # datetime's __eq__ can't compare a None offset and a non-None offset. For these equivalence semantics, a None
    # offset (unknown local offset) is treated equivalently to a +00:00.
    if a.tzinfo is None:
        a = a.replace(tzinfo=OffsetTZInfo())
    if b.tzinfo is None:
        b = b.replace(tzinfo=OffsetTZInfo())
    # datetime's __eq__ implementation compares instants; offsets and precision need not be equal.
    return a == b
446130
def force_utc(time, name='field', precision=6):
    """"""
    if not isinstance(time, datetime.datetime):
        raise CloudValueError("%s should be of type datetime" % (name,))
    clip = 6 - precision
    timestring = time.isoformat()
    if clip:
        timestring = timestring[:-clip]
    return timestring + "Z"
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);
		}
	}
207923
synchronized TimestampData getCurrentTimestamp(boolean withZone) {

        resetCurrentTimestamp();

        if (withZone) {
            if (currentTimestamp == null) {
                int nanos = (int) (currentMillis % 1000) * 1000000;

                currentTimestamp = new TimestampData((currentMillis / 1000),
                                                     nanos, timeZoneSeconds);
            }

            return currentTimestamp;
        } else {
            if (localTimestamp == null) {
                int nanos = (int) (currentMillis % 1000) * 1000000;

                localTimestamp = new TimestampData(currentMillis / 1000
                                                   + timeZoneSeconds, nanos,
                                                       0);
            }

            return localTimestamp;
        }
    }
584583
def to_datetime(timestamp):
    """"""
    return dt.fromtimestamp(time.mktime(
        time.localtime(int(str(timestamp)[:10]))))
1056076
public static OffsetDateTime getOffsetDateTime(long timestamp,
            ZoneOffset zoneOffset) {
        return Instant.ofEpochMilli(timestamp).atOffset(zoneOffset);
    }
1232253
def humanize_timestamp(utc_timestamp, verbose=False):
        

        timedelta = datetime.utcnow() - datetime.utcfromtimestamp(utc_timestamp)

        seconds = int(timedelta.total_seconds())
        if seconds < 60:
            return 'moments ago' if verbose else '0min'

        minutes = seconds // 60
        if minutes < 60:
            if verbose and minutes == 1:
                return '1 minutes ago'
            elif verbose:
                return '%d minutes ago' % minutes
            else:
                return '%dmin' % minutes

        hours = minutes // 60
        if hours < 24:
            if verbose and hours == 1:
                return '1 hour ago'
            elif verbose:
                return '%d hours ago' % hours
            else:
                return '%dhr' % hours

        days = hours // 24
        if days < 30:
            if verbose and days == 1:
                return '1 day ago'
            elif verbose:
                return '%d days ago' % days
            else:
                return '%dday' % days

        months = days // 30.4
        if months < 12:
            if verbose and months == 1:
                return '1 month ago'
            elif verbose:
                return '%d months ago' % months
            else:
                return '%dmonth' % months

        years = months // 12
        if verbose and years == 1:
            return '1 year ago'
        elif verbose:
            return '%d years ago' % years
        else:
            return '%dyr' % years
522584
def execute_cast_timestamp_to_timestamp(op, data, type, **kwargs):
    """"""
    input_timezone = data.tz
    target_timezone = type.timezone

    if input_timezone == target_timezone:
        return data

    if input_timezone is None or target_timezone is None:
        return data.tz_localize(target_timezone)

    return data.tz_convert(target_timezone)
899681
def TimestampToRDFDatetime(timestamp):
  """"""
  # TODO(hanuszczak): `timestamp` should be of MySQL type `Decimal`. However,
  # it is unclear where this type is actually defined and how to import it in
  # order to have a type assertion.
  if timestamp is None:
    return None
  else:
    micros = int(1000000 * timestamp)
    return rdfvalue.RDFDatetime.FromMicrosecondsSinceEpoch(micros)
587188
def _utc_float(self):
        """"""
        tai = self.tai
        leap_dates = self.ts.leap_dates
        leap_offsets = self.ts.leap_offsets
        leap_reverse_dates = leap_dates + leap_offsets / DAY_S
        i = searchsorted(leap_reverse_dates, tai, 'right')
        return tai - leap_offsets[i] / DAY_S
614203
def get_utc_date(entry):
    """"""
    if entry['numeric_date_stamp'] == '0':
        entry['numeric_date_stamp_utc'] = '0'
        return entry

    else:
        if '.' in entry['numeric_date_stamp']:
            t = datetime.strptime(entry['numeric_date_stamp'],
                    '%Y%m%d%H%M%S.%f')
        else:
            t = datetime.strptime(entry['numeric_date_stamp'],
                    '%Y%m%d%H%M%S')
        tdelta = timedelta(hours = int(entry['tzone'][1:3]),
                minutes = int(entry['tzone'][3:5]))

        if entry['tzone'][0] == '-':
            ut = t + tdelta
        else:
            ut = t - tdelta

        entry['numeric_date_stamp_utc'] = ut.strftime('%Y%m%d%H%M%S.%f')

        return entry
147973
def getUTC(self, utcoffset):
        
        newTime = (self.value - utcoffset.value) % 24
        return Time(newTime)
152236
def _append_utc_datetime(self, tag, format, ts, precision, header):
        """"""

        if ts is None:
            t = datetime.datetime.utcnow()
        elif type(ts) is float:
            t = datetime.datetime.utcfromtimestamp(ts)
        else:
            t = ts

        s = t.strftime(format)
        if precision == 3:
            s += ".%03d" % (t.microsecond / 1000)
        elif precision == 6:
            s += ".%06d" % t.microsecond
        elif precision != 0:
            raise ValueError("Precision should be one of 0, 3 or 6 digits")

        return self.append_pair(tag, s, header=header)
311665
function utc_offset() {
      if (this.zone == ICAL.Timezone.localTimezone ||
          this.zone == ICAL.Timezone.utcTimezone) {
        return 0;
      } else {
        return this.zone.utcOffset(this);
      }
    }
1130664
def timezone(utcoffset):
    '''
    

    '''

    hours, seconds = divmod(abs(utcoffset), 3600)
    minutes = round(float(seconds) / 60)

    if utcoffset >= 0:
        sign = '+'
    else:
        sign = '-'
    return '{0}{1:02d}:{2:02d}'.format(sign, int(hours), int(minutes))
783162
public static UtcOffset parse(TimeZone timezone) {
		long offset = timezone.getOffset(System.currentTimeMillis());
		return new UtcOffset(offset);
	}