Convert time to hour, minute
545102
def convert_time_to_hour_minute(hour, minute, convention):
    
    if hour is None:
        hour = 0
    if minute is None:
        minute = 0
    if convention is None:
        convention = 'am'

    hour = int(hour)
    minute = int(minute)

    if convention.lower() == 'pm':
        hour += 12

    return {'hours': hour, 'minutes': minute}
685135
def time_string(seconds):
    """"""
    s = int(round(seconds))  # round to nearest second
    h, s = divmod(s, 3600)  # get hours and remainder
    m, s = divmod(s, 60)  # split remainder into minutes and seconds
    return "%2i:%02i:%02i" % (h, m, s)
637056
function timeInMs(time) {
	var HOUR_IN_MS = 3.6e+6,
		DAY_IN_MS = HOUR_IN_MS * 24,
		WK_IN_MS = DAY_IN_MS * 7,
		MS_DICTIONARY = {
			'weeks': WK_IN_MS,
			'week': WK_IN_MS,
			'w': WK_IN_MS,
			'days': DAY_IN_MS,
			'day': DAY_IN_MS,
			'd': DAY_IN_MS,
			'hours': HOUR_IN_MS,
			'hour': HOUR_IN_MS,
			'h': HOUR_IN_MS
		};

	var duration = parseInt(time, 10);
	var interval = time.replace(/\d*[\d]/, '').trim();

	if (Object.keys(MS_DICTIONARY).indexOf(interval) < 0) {
		throw new Error('Interval is invalid. The ttl must be of weeks, days, or hours');
	}

	return MS_DICTIONARY[interval] * duration;
}
839776
def setTime(self, time):
        
        hour = time.hour()
        minute = time.minute()
        second = time.second()

        if not self.isMilitaryTime():
            if hour > 12:
                hour -= 12
                self._timeOfDayCombo.setCurrentIndex(1)
            else:
                self._timeOfDayCombo.setCurrentIndex(0)
            hour = str(hour)
        else:
            hour = '{0:02d}'.format(hour)

        nearest = lambda x: int(round(x/5.0)*5.0)

        self._hourCombo.setCurrentIndex(self._hourCombo.findText(hour))
        self._minuteCombo.setCurrentIndex(self._minuteCombo.findText('{0:02d}'.format(nearest(minute))))
        self._secondCombo.setCurrentIndex(self._secondCombo.findText('{0:02d}'.format(nearest(second))))
999326
function formatTime(time) {
				if (time == '') {
					if (settings.required) return settings.duration ? '0:00' : '00:00';
					else return time;
				}
				if ((new RegExp('^(-|\\+)?([0-9]+)(.([0-9]{1,2})?)?$', 'i')).test(time)) {
					var hour = parseInt(RegExp.$2);
					var min = parseInt(RegExp.$4);
					if (!min) min = 0;
					var negative = settings.duration && settings.durationNegative && RegExp.$1 == '-' ? true : false;
					if (hour >= 24 && !settings.duration) hour = hour % 24;
					if (min >= 60) min = min % 60;
					if (settings.precision != 1) {
						var f = Math.floor(min / settings.precision);
						min = f * settings.precision + (Math.round((min - f * settings.precision) / settings.precision) == 1 ? settings.precision : 0);
						if (min >= 60) min = 0;
					}
					time = (negative ? '-' : '') + (hour < 10 && !settings.duration ? '0' : '') + hour + settings.separator + (RegExp.$3 ? (min < 10 ? '0' : '') + min : '00');
				}
				else if ((new RegExp('^(-|\\+)?.([0-9]{1,2})')).test(time)) {
					var min = parseInt(RegExp.$2);
					var negative = settings.duration && settings.durationNegative && RegExp.$1 == '-' ? true : false;
					if (min >= 60) min = min % 60;
					time = (negative && min > 0 ? '-' : '') + '0' + (!settings.duration ? '0' : '') + settings.separator + (min < 10 ? '0' : '') + min;
				}
				else {
					time = '0' + (!settings.duration ? '0' : '') + settings.separator + '00';
				}
				return (settings.duration && settings.useDurationPlusSign && !time.match(/^\-/) && !time.match(/^0+:00$/) ? '+' : '') + time;
			}
1168609
def humanize_hours(total_hours, frmt='{hours:02d}:{minutes:02d}:{seconds:02d}',
                   negative_frmt=None):
    """"""
    seconds = int(float(total_hours) * 3600)
    return humanize_seconds(seconds, frmt, negative_frmt)
1343856
def time_to_text(time):
    """"""
    
    if time < 0.001:
        return str(round(time * 1000000)) + " µs"
    elif time < 1:
        return str(round(time * 1000)) + " ms"
    elif time < 60:
        return str(round(time, 1)) + " s"
    else:
        return str(round(time / 60, 1)) + " min"
302891
def replace(self, hour=None, minute=None, second=None, microsecond=None,
                tzinfo=True):
        """"""
        if hour is None:
            hour = self.hour
        if minute is None:
            minute = self.minute
        if second is None:
            second = self.second
        if microsecond is None:
            microsecond = self.microsecond
        if tzinfo is True:
            tzinfo = self.tzinfo
        _check_time_fields(hour, minute, second, microsecond)
        _check_tzinfo_arg(tzinfo)
        return time(hour, minute, second, microsecond, tzinfo)
843109
def _calculate_hour_and_minute(float_hour):
        """"""
        hour, minute = int(float_hour), int(round((float_hour - int(float_hour)) * 60))
        if minute == 60:
            return hour + 1, 0
        else:
            return hour, minute
582818
function( time ) {
		var h, m, s;

		if ( time > TIME_MINUTE ) {
			m = parseInt( time / TIME_MINUTE, 10 );
			s = ( time % TIME_MINUTE ) / TIME_SECOND;
			return m + 'mins, ' + s + 's';
		}
		else if ( time > TIME_SECOND ) {
			return ( time / TIME_SECOND ) + 's';
		}
		else {
			return time + 'ms';
		}
	}
113491
def format_time(seconds):
    """"""
    minute = 60
    hour = minute * 60
    day = hour * 24
    week = day * 7

    result = []
    for name, dur in [
            ('week', week), ('day', day), ('hour', hour),
            ('minute', minute), ('second', 1)
    ]:
        if seconds > dur:
            value = seconds // dur
            result.append(
                '{0} {1}{2}'.format(int(value), name, 's' if value > 1 else '')
            )
            seconds = seconds % dur
    return ' '.join(result)
49589
def _round_to(dt, hour, minute, second):
    
    new_dt = dt.replace(hour=hour, minute=minute, second=second)
    if new_dt == dt:
        return new_dt
    elif new_dt < dt:
        before = new_dt
        after = new_dt + timedelta(days=1)
    elif new_dt > dt:
        before = new_dt - timedelta(days=1)
        after = new_dt

    d1 = dt - before
    d2 = after - dt

    if d1 < d2:
        return before
    elif d1 > d2:
        return after
    else:
        return before
223440
def _encode_time(mtime: float):
    """"""
    dt = arrow.get(mtime)
    dt = dt.to("local")
    date_val = ((dt.year - 1980) << 9) | (dt.month << 5) | dt.day
    secs = dt.second + dt.microsecond / 10**6
    time_val = (dt.hour << 11) | (dt.minute << 5) | math.floor(secs / 2)
    return (date_val << 16) | time_val
1044644
def minute(date)
      time = [pad(date.hour.to_s), pad(date.minute.to_s)].join(':')
      [time, day(date)].join(' ')
    end
1084165
def to_time(time, granularity):
    """"""
    if not granularity:
        if type(time) is datetime.date:
            return format_date(time)
        else:
            return format_time(time)
    if granularity == GRANULARITY.HOUR:
        return format_time(remove_minutes(time))
    elif granularity == GRANULARITY.DAY:
        return format_date(remove_hours(time))
    else:
        return format_time(time)
1085980
function(time){
  var tempC = parseFloat(time.find('temperature').eq(0).attr('value'));
  return {
    hoursFromNow: Math.ceil(((new Date(time.attr("from"))).getTime() - (new Date()).getTime()) / 1000 / 60 / 60),

    // Celcius is kept decimal since met.no returns a pleasant formatted value. 
    // Fahrenheit is rounded for reasons of laziness. 
    // TODO: format Fahrenheit value.
    tempC: tempC,
    tempF: Math.round((9 / 5 * tempC) + 32)
  };
}
687988
def nsamples_to_hourminsec(x, pos):
    '''
    '''

    h, m, s = hourminsec(x/16.0)
    return '{:.0f}h {:2.0f}′ {:2.1f}″'.format(h, m, s)