Convert seconds to days, hours, minutes, seconds.

        Using days as the largest unit of time.  Blindly using the days in
        `time.gmtime()` will fail if it's more than one month (days > 31).
550694
def secs_to_dhms(time_in_secs):
        
        days = int(time_in_secs / SECS_IN_DAY)
        remaining_secs = time_in_secs % SECS_IN_DAY
        hours = int(remaining_secs / SECS_IN_HOUR)
        remaining_secs = remaining_secs % SECS_IN_HOUR
        mins = int(remaining_secs / SECS_IN_MIN)
        secs = int(remaining_secs % SECS_IN_MIN)
        return days, hours, mins, secs
31936
def seconds2str(seconds):
    """"""

    if seconds < 0:
        return "{0:.3g}s".format(seconds)
    elif math.isnan(seconds):
        return "NaN"
    elif math.isinf(seconds):
        return "Inf"

    m, s = divmod(seconds, 60)
    h, m = divmod(m, 60)
    if h >= 1:
        return "{0:g}h {1:02g}m {2:.3g}s".format(h, m, s)
    elif m >= 1:
        return "{0:02g}m {1:.3g}s".format(m, s)
    else:
        return "{0:.3g}s".format(s)
502031
def hours_minutes_seconds(self):
        
        minutes, seconds = symmetric_divmod(self[2], 60)
        hours, minutes = symmetric_divmod(minutes, 60)
        return hours, minutes, float(seconds) + self[3]
1361966
def _to_micros(dur):
    """"""
    if hasattr(dur, 'total_seconds'):
        return int(dur.total_seconds() * 10e5)
    # Python 2.6
    return dur.microseconds + (dur.seconds + dur.days * 24 * 3600) * 1000000
369491
function secondsToTime(secs) {
  var days = Math.floor(secs / (60 * 60 * 24))
    , divisor_for_hours = secs % (60 * 60 * 24)
    , hours = Math.floor(divisor_for_hours / (60 * 60))
    , divisor_for_minutes = secs % (60 * 60)
    , minutes = Math.floor(divisor_for_minutes / 60)
    , divisor_for_seconds = divisor_for_minutes % 60
    , seconds = Math.ceil(divisor_for_seconds);
  return {"d": days, "h": hours, "m": minutes, "s": seconds};
}
392156
def format_time_large(seconds):
    

    if not isinstance(seconds, (int, float)):
        return str(seconds)

    if math.isnan(seconds):
        return "-"

    seconds = int(round(seconds))
    if abs(seconds)<60:
        return "{:d}".format(seconds)
    else:
        minutes = int(seconds/60)
        seconds %= 60
        if abs(minutes)<60:
            return "{:d}:{:02d}".format(minutes,seconds)
        else:
            hours = int(minutes/60)
            minutes %= 60
            if abs(hours)<24:
                return "{:d}:{:02d}:{:02d}".format(hours,minutes,seconds)
            else:
                days = int(hours/24)
                hours %= 24
                return "{:d}:{:02d}:{:02d}:{:02d}".format(
                    days,hours,minutes,seconds)
800069
public static function secondsTo($unit, $seconds)
    {
        $method = $unit.'ToSeconds';

        return  (float) $seconds / (float) self::$method();
    }
21197
def parse_seconds(value):
        '''
        
        '''
        svalue = str(value)
        colons = svalue.count(':')
        if colons == 2:
            hours, minutes, seconds = [int(v) for v in svalue.split(':')]
        elif colons == 1:
            hours, minutes = [int(v) for v in svalue.split(':')]
            seconds = 0
        elif colons == 0:
            hours = 0
            minutes = 0
            seconds = int(svalue)
        else:
            raise ValueError('Must be in seconds or HH:MM:SS format')
        return Seconds.from_hms(hours, minutes, seconds)
1209428
public static function Seconds($Seconds) {
      if (!is_numeric($Seconds)) {
         $Seconds = abs(time() - self::ToTimestamp($Seconds));
      }

      $Minutes = round($Seconds/60);
      $Hours = round($Seconds/3600);
      $Days = round($Seconds/86400);
      $Weeks = round($Seconds/604800);
      $Months = round($Seconds/2629743.83);
      $Years = round($Seconds/31556926);

      if ($Seconds < 60)
         return sprintf(Plural($Seconds, '%s second', '%s seconds'), $Seconds);
      elseif ($Minutes < 60)
         return sprintf(Plural($Minutes, '%s minute', '%s minutes'), $Minutes);
      elseif ($Hours < 24)
         return sprintf(Plural($Hours, '%s hour', '%s hours'), $Hours);
      elseif ($Days < 7)
         return sprintf(Plural($Days, '%s day', '%s days'), $Days);
      elseif ($Weeks < 4)
         return sprintf(Plural($Weeks, '%s week', '%s weeks'), $Weeks);
      elseif ($Months < 12)
         return sprintf(Plural($Months, '%s month', '%s months'), $Months);
      else
         return sprintf(Plural($Years, '%s year', '%s years'), $Years);
   }
1154752
def seconds_to_time(x):
    """"""
    t = int(x * 10**6)
    ms = t % 10**6
    t = t // 10**6
    s = t % 60
    t = t // 60
    m = t % 60
    t = t // 60
    h = t
    return time(h, m, s, ms)
533490
def timedelta_seconds(timedelta):
    """"""
    return (timedelta.total_seconds() if hasattr(timedelta, "total_seconds")
            else timedelta.days * 24 * 3600 + timedelta.seconds +
                 timedelta.microseconds / 1000000.)
343474
def readable_time_delta(seconds):
    
    days = seconds // 86400
    seconds -= days * 86400
    hours = seconds // 3600
    seconds -= hours * 3600
    minutes = seconds // 60

    m_suffix = 's' if minutes != 1 else ''
    h_suffix = 's' if hours != 1 else ''
    d_suffix = 's' if days != 1 else ''

    retval = u'{0} minute{1}'.format(minutes, m_suffix)

    if hours != 0:
        retval = u'{0} hour{1} and {2}'.format(hours, h_suffix, retval)

    if days != 0:
        retval = u'{0} day{1}, {2}'.format(days, d_suffix, retval)

    return retval
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'])
479137
def clip_to_seconds(m: Union[int, pd.Series]) -> Union[int, pd.Series]:
        """"""
        return m // pd.Timedelta(1, unit='s').value
1347953
def to_seconds(base = nil)
      valid_base?(base)
      return factor(base) * atom if base.nil?
      target = ::Time.new(base.year + atom.to_i, base.month, base.day, base.hour, base.minute, base.second, base.zone)

      target - base.to_time
    end
462085
def get_time_diff_days(start, end):
    '''   '''

    if start is None or end is None:
        return None

    if type(start) is not datetime.datetime:
        start = parser.parse(start).replace(tzinfo=None)
    if type(end) is not datetime.datetime:
        end = parser.parse(end).replace(tzinfo=None)

    seconds_day = float(60 * 60 * 24)
    diff_days = (end - start).total_seconds() / seconds_day
    diff_days = float('%.2f' % diff_days)

    return diff_days
1372063
def duration_to_number(duration, units='seconds'):
    
    if isinstance(duration, (int, float, long)):
        return duration
    elif isinstance(duration, (datetime.timedelta,)):
        if units == 'seconds':
            return duration.total_seconds()
        else:
            msg = 'unit "%s" is not supported' % units
            raise NotImplementedError(msg)
    elif duration == inf or duration == -inf:
        msg = "Can't convert infinite duration to number"
        raise ValueError(msg)
    else:
        msg = 'duration is an unknown type (%s)' % duration
        raise TypeError(msg)