Calculate degree, minute second from decimal degree
969377
def _calc_degreeminutes(decimal_degree):
        '''
        
        '''
        sign = compare(decimal_degree, 0) # Store whether the coordinate is negative or positive
        decimal_degree = abs(decimal_degree)
        degree = decimal_degree//1 # Truncate degree to be an integer
        decimal_minute = (decimal_degree - degree)*60. # Calculate the decimal minutes
        minute = decimal_minute//1 # Truncate minute to be an integer
        second = (decimal_minute - minute)*60. # Calculate the decimal seconds
        # Finally, re-impose the appropriate sign
        degree = degree*sign
        minute = minute*sign
        second = second*sign
        return (degree, minute, decimal_minute, second)
338851
def time_from_hhmmssmmm(string, decimal_separator="."):
    
    if decimal_separator == ",":
        pattern = HHMMSS_MMM_PATTERN_COMMA
    else:
        pattern = HHMMSS_MMM_PATTERN
    v_length = TimeValue("0.000")
    try:
        match = pattern.search(string)
        if match is not None:
            v_h = int(match.group(1))
            v_m = int(match.group(2))
            v_s = int(match.group(3))
            v_f = TimeValue("0." + match.group(4))
            v_length = v_h * 3600 + v_m * 60 + v_s + v_f
    except:
        pass
    return v_length
499707
function secondsToTimeParam(seconds) {
	var h = Math.floor(seconds / 3600);
	var m = Math.floor((seconds / 60) % 60);
	var s = seconds % 60;
	var param = '';

	if (h > 0) {
		param += h + 'h';
	}

	if (m > 0) {
		param += m + 'm';
	}

	if (s > 0) {
		param += s + 's';
	}

	return param;
}
352494
def todmsstr(origin):
    

    degrees, minutes, seconds = todms(origin)
    return u'%d°%d\'%f"' % (degrees, minutes, seconds)
1356474
def timedelta2millisecond(td):
    """"""
    milliseconds = td.days * 24 * 60 * 60 * 1000
    milliseconds += td.seconds * 1000
    milliseconds += td.microseconds / 1000
    return milliseconds
743728
function(mod) {
			var seconds = this.time;
			
			if(mod) {
				if(seconds == 60) {
					seconds = 0;
				}
				else {
					seconds = seconds % 60;
				}
			}
			
			return Math.ceil(seconds);
		}
554030
function getMilliseconds( time ) {
  if ( typeof time == 'number' ) {
    return time;
  }
  var matches = time.match( /(^\d*\.?\d*)(\w*)/ );
  var num = matches && matches[1];
  var unit = matches && matches[2];
  if ( !num.length ) {
    return 0;
  }
  num = parseFloat( num );
  var mult = msUnits[ unit ] || 1;
  return num * mult;
}
887430
def get_seconds(self):
        
        parsed = self.parse_hh_mm_ss()  # get times
        total_seconds = parsed.second
        total_seconds += parsed.minute * 60.0
        total_seconds += parsed.hour * 60.0 * 60.0
        return total_seconds
828032
def decimal_to_dms(value, precision):
    '''
    
    '''
    deg = math.floor(value)
    min = math.floor((value - deg) * 60)
    sec = math.floor((value - deg - min / 60) * 3600 * precision)

    return ((deg, 1), (min, 1), (sec, precision))
222843
def _get_decimal_from_datetime(time):
    '''
    
    '''

    # Get decimal seconds from seconds + microseconds
    temp_seconds = np.float(time.second) + (np.float(time.microsecond) / 1.0E6)
    return decimal_time(np.array([time.year], dtype=int),
                        np.array([time.month], dtype=int),
                        np.array([time.day], dtype=int),
                        np.array([time.hour], dtype=int),
                        np.array([time.minute], dtype=int),
                        np.array([temp_seconds], dtype=int))
301888
function timeCode(seconds, delim = ':') {
    // const h = Math.floor(seconds / 3600);
    // const m = Math.floor((seconds % 3600) / 60);
    const m = Math.floor(seconds / 60);
    const s = Math.floor((seconds % 3600) % 60);
    // const hr = (h < 10 ? '0' + h + delim : h + delim);
    const mn = (m < 10 ? '0' + m : m) + delim;
    const sc = (s < 10 ? '0' + s : s);
    // return hr + mn + sc;
    return mn + sc;
}
1235694
def FromNanoseconds(self, nanos):
    """"""
    self.seconds = nanos // _NANOS_PER_SECOND
    self.nanos = nanos % _NANOS_PER_SECOND
847936
function getDistanceInKilometers(p1, p2) {
  // Credit: adapts code for Haversine formula and degrees-to-radian conversion found at:
  // http://www.movable-type.co.uk/scripts/latlong.html

  var R = 6371; // earth's radius in kilometers
  var dLat = degreesToRadians(p2.lat - p1.lat);
  var dLon = degreesToRadians(p2.lng - p1.lng); 
  var lat1 = degreesToRadians(p1.lat);
  var lat2 = degreesToRadians(p2.lat);

  var a = 
    Math.sin(dLat/2) * Math.sin(dLat/2)
    + Math.sin(dLon/2) * Math.sin(dLon/2)
    * Math.cos(lat1) * Math.cos(lat2);

  var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
  var distance = R * c; // kilomter
  return distance;
}
221160
def dec2dms(dec):
    
    DEGREE = 360.
    HOUR = 24.
    MINUTE = 60.
    SECOND = 3600.

    dec = float(dec)
    sign = np.copysign(1.0,dec)

    fdeg = np.abs(dec)
    deg = int(fdeg)
    
    fminute = (fdeg - deg)*MINUTE
    minute = int(fminute)
    
    second = (fminute - minute)*MINUTE

    deg = int(deg * sign)
    return (deg, minute, second)
1227940
def todms(origin):
    

    degrees, minutes = tomindec(origin)
    seconds = (minutes % 1) * 60

    return degrees, int(minutes), seconds
29512
def decimal_date(dateobs, timeobs=None):
    """"""

    year, month, day = dateobs.split('-')
    if timeobs is not None:
        hr, min, sec = timeobs.split(':')
    else:
        hr, min, sec = 0, 0, 0

    rdate = datetime.datetime(int(year), int(month), int(day), int(hr),
                              int(min), int(sec))
    dday = (float(rdate.strftime("%j")) + rdate.hour / 24.0 +
            rdate.minute / (60. * 24) + rdate.second / (3600 * 24.)) / 365.25
    ddate = int(year) + dday

    return ddate
48904
def stringify_seconds(seconds=0):
    
    seconds = int(seconds)
    minutes = seconds / 60
    ti = {'h': 0, 'm': 0, 's': 0}

    if seconds > 0:
        ti['s'] = seconds % 60
        ti['m'] = minutes % 60
        ti['h'] = minutes / 60

    return "%dh %dm %ds" % (ti['h'], ti['m'], ti['s'])