method casts given timeperiod accordingly to time qualifier.
    For example, will cast session time format of 20100101193412 to 2010010119 with QUALIFIER_HOURLY
17986
def cast_to_time_qualifier(time_qualifier, timeperiod):
    

    if time_qualifier == QUALIFIER_HOURLY:
        date_format = SYNERGY_HOURLY_PATTERN
    elif time_qualifier == QUALIFIER_DAILY:
        date_format = SYNERGY_DAILY_PATTERN
    elif time_qualifier == QUALIFIER_MONTHLY:
        date_format = SYNERGY_MONTHLY_PATTERN
    elif time_qualifier == QUALIFIER_YEARLY:
        date_format = SYNERGY_YEARLY_PATTERN
    else:
        raise ValueError('unknown time qualifier: {0}'.format(time_qualifier))

    pattern = define_pattern(timeperiod)
    t = datetime.strptime(timeperiod, pattern)
    return t.strftime(date_format)
641940
public static DateTime toDateAdvanced(Object o, TimeZone timezone) throws PageException {
	if (o instanceof Date) {
	    if (o instanceof DateTime) return (DateTime) o;
	    return new DateTimeImpl((Date) o);
	}
	else if (o instanceof Castable) return ((Castable) o).castToDateTime();
	else if (o instanceof String) {
	    DateTime dt = toDateAdvanced((String) o, timezone, null);
	    if (dt == null) throw new ExpressionException("can't cast [" + o + "] to date value");
	    return dt;
	}
	else if (o instanceof Number) return util.toDateTime(((Number) o).doubleValue());
	else if (o instanceof ObjectWrap) return toDateAdvanced(((ObjectWrap) o).getEmbededObject(), timezone);
	else if (o instanceof Calendar) {

	    return new DateTimeImpl((Calendar) o);
	}
	throw new ExpressionException("can't cast [" + Caster.toClassName(o) + "] to date value");
    }
283437
@Override
	public void writeValue(TimeValue value, Resource resource)
			throws RDFHandlerException {
		this.rdfWriter.writeTripleValueObject(resource, RdfWriter.RDF_TYPE,
				RdfWriter.WB_TIME_VALUE);

		this.rdfWriter.writeTripleValueObject(resource, RdfWriter.WB_TIME,
				TimeValueConverter.getTimeLiteral(value, this.rdfWriter));

		this.rdfWriter.writeTripleIntegerObject(resource,
				RdfWriter.WB_TIME_PRECISION, value.getPrecision());
		this.rdfWriter.writeTripleIntegerObject(resource,
				RdfWriter.WB_TIME_TIMEZONE,
				value.getTimezoneOffset());
		this.rdfWriter.writeTripleUriObject(resource,
				RdfWriter.WB_TIME_CALENDAR_MODEL,
				value.getPreferredCalendarModel());
	}
800150
private void assertClientMayUpdate(int hour) {
        OAuthContext oauth = getOAuthContext();
        List<OAuthPermission> perms = oauth.getPermissions();
        boolean checkPassed = false;
        for (OAuthPermission perm : perms) {
            if (perm.getPermission().startsWith(OAuthConstants.UPDATE_CALENDAR_SCOPE)) {
                int authorizedHour = Integer.valueOf(perm.getPermission()
                    .substring(OAuthConstants.UPDATE_CALENDAR_SCOPE.length()));
                if (authorizedHour == 24 || authorizedHour == hour) {
                    checkPassed = true;
                }
            }
        }
        if (!checkPassed) {
            throw new WebApplicationException(403);
        }
    }
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)
878557
function convertRawTime(rawColumnValue, column, context)
{
  var columnScale = column.getScale();

  // the values might be big so use BigNumber to do arithmetic
  var valFracSecsBig =
      new BigNumber(rawColumnValue).times(Math.pow(10, columnScale));

  return convertRawTimestampHelper(
      valFracSecsBig,
      columnScale,
      'UTC',
      context.format).toSfTime();
}
709356
function convertTimestampToBigEndian(timestamp) {
  // The timestamp parameter in Big-Endian UInt-64 format
  var buffer = new Buffer(8);
  buffer.fill(0);

  var high = ~~(timestamp / 0xffffffff); // jshint ignore:line
  var low = timestamp % (0xffffffff + 0x1); // jshint ignore:line

  buffer.writeUInt32BE(parseInt(high, 10), 0);
  buffer.writeUInt32BE(parseInt(low, 10), 4);

  return buffer;
}
695750
public Timestamp getInternalTimestamp(ColumnInformation columnInfo, Calendar userCalendar,
      TimeZone timeZone) throws SQLException {
    if (lastValueWasNull()) {
      return null;
    }
    if (length == 0) {
      lastValueNull |= BIT_LAST_FIELD_NULL;
      return null;
    }

    int year = 1970;
    int month = 0;
    int day = 0;
    int hour = 0;
    int minutes = 0;
    int seconds = 0;
    int microseconds = 0;

    switch (columnInfo.getColumnType()) {
      case TIME:
        Calendar calendar = userCalendar != null ? userCalendar : Calendar.getInstance();

        boolean negate = false;
        if (length > 0) {
          negate = (buf[pos] & 0xff) == 0x01;
        }
        if (length > 4) {
          day = ((buf[pos + 1] & 0xff)
              + ((buf[pos + 2] & 0xff) << 8)
              + ((buf[pos + 3] & 0xff) << 16)
              + ((buf[pos + 4] & 0xff) << 24));
        }
        if (length > 7) {
          hour = buf[pos + 5];
          minutes = buf[pos + 6];
          seconds = buf[pos + 7];
        }

        if (length > 8) {
          microseconds = ((buf[pos + 8] & 0xff)
              + ((buf[pos + 9] & 0xff) << 8)
              + ((buf[pos + 10] & 0xff) << 16)
              + ((buf[pos + 11] & 0xff) << 24));
        }
        year = 1970;
        month = 1;
        day = ((negate ? -1 : 1) * day) + 1;
        hour = (negate ? -1 : 1) * hour;
        break;

      case STRING:
      case VARSTRING:
        String rawValue = new String(buf, pos, length, StandardCharsets.UTF_8);
        if (rawValue.startsWith("0000-00-00 00:00:00")) {
          lastValueNull |= BIT_LAST_ZERO_DATE;
          return null;
        }

        if (rawValue.length() >= 4) {
          year = Integer.parseInt(rawValue.substring(0, 4));
          if (rawValue.length() >= 7) {
            month = Integer.parseInt(rawValue.substring(5, 7));
            if (rawValue.length() >= 10) {
              day = Integer.parseInt(rawValue.substring(8, 10));
              if (rawValue.length() >= 19) {
                hour = Integer.parseInt(rawValue.substring(11, 13));
                minutes = Integer.parseInt(rawValue.substring(14, 16));
                seconds = Integer.parseInt(rawValue.substring(17, 19));
              }
              microseconds = extractNanos(rawValue) / 1000000;
            }
          }
        }
        break;

      default:
        year = ((buf[pos] & 0xff) | (buf[pos + 1] & 0xff) << 8);
        month = buf[pos + 2];
        day = buf[pos + 3];
        if (length > 4) {
          hour = buf[pos + 4];
          minutes = buf[pos + 5];
          seconds = buf[pos + 6];

          if (length > 7) {
            microseconds = ((buf[pos + 7] & 0xff)
                + ((buf[pos + 8] & 0xff) << 8)
                + ((buf[pos + 9] & 0xff) << 16)
                + ((buf[pos + 10] & 0xff) << 24));
          }
        }
    }

    Calendar calendar;
    if (userCalendar != null) {
      calendar = userCalendar;
    } else if (columnInfo.getColumnType().getSqlType() == Types.TIMESTAMP) {
      calendar = Calendar.getInstance(timeZone);
    } else {
      calendar = Calendar.getInstance();
    }

    Timestamp tt;
    synchronized (calendar) {
      calendar.clear();
      calendar.set(year, month - 1, day, hour, minutes, seconds);
      tt = new Timestamp(calendar.getTimeInMillis());
    }
    tt.setNanos(microseconds * 1000);
    return tt;
  }
805866
def _cast(self, value, format=None, **opts):
        """"""
        if format is not None:
            return datetime.strptime(value, format)
        return dateutil.parser.parse(value)
1337920
public static Matcher<Date> hasHour(final int hour, final ClockPeriod clockPeriod) {
        return new IsDateWithTime(hour, clockPeriod, null, null, null);
    }
490484
def cast_value(v)
      return nil if v.nil?
      if @type == :date
        self.style = STYLE_DATE if self.style == 0
        v
      elsif (@type == :time && v.is_a?(Time)) || (@type == :time && v.respond_to?(:to_time))
        self.style = STYLE_DATE if self.style == 0
        # one simple little fix.  I DO NOT WANT TIME IN LOCAL TIME!
        unless v.is_a?(Time)
          v = v.respond_to?(:to_time) ? v.to_time : v
        end
        v
      elsif @type == :float
        v.to_f
      elsif @type == :integer
        v.to_i
      elsif @type == :boolean
        v ? 1 : 0
      elsif @type == :iso_8601
        #consumer is responsible for ensuring the iso_8601 format when specifying this type
        v
      else
        @type = :string
        # TODO find a better way to do this as it accounts for 30% of
        # processing time in benchmarking...
        Axlsx::trust_input ? v.to_s : ::CGI.escapeHTML(v.to_s)
      end
    end
263268
def cast_callback(value):
        
        # Postgresql / MySQL drivers change the format on 'TIMESTAMP' columns;

        if 'T' in value:
            value = value.replace('T', ' ')

        return datetime.strptime(value.split('.')[0], '%Y-%m-%d %H:%M:%S')
1254793
def cast_datetime_filter(value):
    
    if isinstance(value, str):
        dtime = parse_datetime(value)

    elif isinstance(value, datetime):
        dtime = value
    else:
        raise ValueError('Received value of type {0}'.format(type(value)))

    return dtime.isoformat()
835785
def _ValidateTimeRange(timerange):
  """"""
  if len(timerange) != 2:
    raise ValueError("Timerange should be a sequence with 2 items.")

  (start, end) = timerange
  precondition.AssertOptionalType(start, rdfvalue.RDFDatetime)
  precondition.AssertOptionalType(end, rdfvalue.RDFDatetime)
1120461
static long comparable(DateValue dv) {
        long comp = (((((long) dv.year()) << 4) + dv.month()) << 5) + dv.day();
        if (dv instanceof TimeValue) {
            TimeValue tv = (TimeValue) dv;
            // We add 1 to comparable for timed values to make sure that timed
            // events are distinct from all-day events, in keeping with
            // DateValue.compareTo.

            // It would be odd if an all day exclusion matched a midnight event on
            // the same day, but not one at another time of day.
            return (((((comp << 5) + tv.hour()) << 6) + tv.minute()) << 6)
                    + tv.second() + 1;
        } else {
            return comp << 17;
        }
    }
1359391
def timedelta2period(duration):
    """"""
    seconds = duration.seconds
    minutes = (seconds % 3600) // 60
    seconds = (seconds % 60)
    return '{0:0>2}:{1:0>2}'.format(minutes, seconds)
354955
function (ISO8601Duration) {
            var isValueNegative = (ISO8601Duration.indexOf("-") >= 0),
                indexOfT = ISO8601Duration.indexOf("T"),
                indexOfH = ISO8601Duration.indexOf("H"),
                indexOfM = ISO8601Duration.indexOf("M"),
                indexOfS = ISO8601Duration.indexOf("S"),
                hours,
                minutes,
                seconds,
                durationInMilliseconds;

            if ((indexOfT === -1) || ((indexOfM !== -1) && (indexOfM < indexOfT)) || (ISO8601Duration.indexOf("D") !== -1) || (ISO8601Duration.indexOf("Y") !== -1)) {
                throw new Error("ISO 8601 timestamps including years, months and/or days are not currently supported");
            }

            if (indexOfH === -1) {
                indexOfH = indexOfT;
                hours = 0;
            }
            else {
                hours = parseInt(ISO8601Duration.slice(indexOfT + 1, indexOfH), 10);
            }

            if (indexOfM === -1) {
                indexOfM = indexOfT;
                minutes = 0;
            }
            else {
                minutes = parseInt(ISO8601Duration.slice(indexOfH + 1, indexOfM), 10);
            }

            seconds = parseFloat(ISO8601Duration.slice(indexOfM + 1, indexOfS));

            durationInMilliseconds = parseInt((((((hours * 60) + minutes) * 60) + seconds) * 1000), 10);
            if (isNaN(durationInMilliseconds)){
                durationInMilliseconds = 0;
            }
            if (isValueNegative) {
                durationInMilliseconds = durationInMilliseconds * -1;
            }

            return durationInMilliseconds;
        }