Transform a DMS string to a decimal representation. Used for LOC records.

@param int    $deg        Degrees
@param int    $min        Minutes
@param float  $sec        Seconds
@param string $hemisphere Either 'N', 'S', 'E', or 'W'

@return float
512033
public static function dmsToDecimal(int $deg, int $min, float $sec, string $hemisphere): float
    {
        $multiplier = ('S' === $hemisphere || 'W' === $hemisphere) ? -1 : 1;

        return $multiplier * ($deg + ($min / 60) + ($sec / 3600));
    }
1058141
@NotNull
    public static String decimalToDegreesMinutesSecondsString(double decimal)
    {
        double[] dms = decimalToDegreesMinutesSeconds(decimal);
        DecimalFormat format = new DecimalFormat("0.##");
        return String.format("%s\u00B0 %s' %s\"", format.format(dms[0]), format.format(dms[1]), format.format(dms[2]));
    }
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};
}
621453
static public function duration($secs) 
    {
        $vals = array('w' => (int)($secs / 86400 / 7), 'd' => $secs / 86400 % 7, 'h' => $secs / 3600 % 24, 'm' => $secs / 60 % 60, 's' => $secs % 60);

        $ret = array();

        $added = false;
        foreach($vals as $k => $v) {
            if($v > 0 || $added) {
                $added = true;
                $ret[] = $v . $k;
            }
        }

        return (string)join(' ', $ret);
    }
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);
   }
1317554
@Nullable
    public static Double degreesMinutesSecondsToDecimal(@NotNull final Rational degs, @NotNull final Rational mins, @NotNull final Rational secs, final boolean isNegative)
    {
        double decimal = Math.abs(degs.doubleValue())
                + mins.doubleValue() / 60.0d
                + secs.doubleValue() / 3600.0d;

        if (Double.isNaN(decimal))
            return null;

        if (isNegative)
            decimal *= -1;

        return decimal;
    }
359347
public function setMin(?string $min) : self
    {
        if ($min !== null) {
            $min = Decimal::parse($min);
        }

        $this->min = $min;

        return $this;
    }
1360870
def todegdec(origin):
    

    # if the input is already a float (or can be converted to float)
    try:
        return float(origin)
    except ValueError:
        pass

    # DMS format
    m = dms_re.search(origin)
    if m:
        degrees = int(m.group('degrees'))
        minutes = float(m.group('minutes'))
        seconds = float(m.group('seconds'))

        return degrees + minutes / 60 + seconds / 3600

    # Degree + Minutes format
    m = mindec_re.search(origin)
    if m:
        degrees = int(m.group('degrees'))
        minutes = float(m.group('minutes'))

        return degrees + minutes / 60
390889
public static function eulerMascheroni(): Decimal
    {
        if (null === self::$EulerMascheroni) {
            self::$EulerMascheroni = Decimal::fromString(
                "0.57721566490153286060651209008240"
            );
        }
        return self::$EulerMascheroni;
    }
202031
def parse_location(location):
    
    def split_dms(text, hemisphere):
        """Split degrees, minutes and seconds string.

        Args:
            text (str): Text to split

        Returns::
            float: Decimal degrees
        """
        out = []
        sect = []
        for i in text:
            if i.isdigit():
                sect.append(i)
            else:
                out.append(sect)
                sect = []
        d, m, s = [float(''.join(i)) for i in out]
        if hemisphere in 'SW':
            d, m, s = [-1 * x for x in (d, m, s)]
        return to_dd(d, m, s)

    for sep in ';, ':
        chunks = location.split(sep)
        if len(chunks) == 2:
            if chunks[0].endswith('N'):
                latitude = float(chunks[0][:-1])
            elif chunks[0].endswith('S'):
                latitude = -1 * float(chunks[0][:-1])
            else:
                latitude = float(chunks[0])
            if chunks[1].endswith('E'):
                longitude = float(chunks[1][:-1])
            elif chunks[1].endswith('W'):
                longitude = -1 * float(chunks[1][:-1])
            else:
                longitude = float(chunks[1])
            return latitude, longitude
        elif len(chunks) == 4:
            if chunks[0].endswith(('s', '"')):
                latitude = split_dms(chunks[0], chunks[1])
            else:
                latitude = float(chunks[0])
                if chunks[1] == 'S':
                    latitude = -1 * latitude
            if chunks[2].endswith(('s', '"')):
                longitude = split_dms(chunks[2], chunks[3])
            else:
                longitude = float(chunks[2])
                if chunks[3] == 'W':
                    longitude = -1 * longitude
            return latitude, longitude
704449
private static function secondsToDuration($seconds)
    {
        $seconds = intval($seconds);
        $hours = floor($seconds / 3600);
        $minutes = floor(($seconds / 60) % 60);
        $seconds = $seconds % 60;

        return "${hours}h ${minutes}m {$seconds}s";
    }
883327
protected function initMinutes( $minutes, $seconds )
   {

      if ( ! TypeTool::IsDecimal( $minutes ) )
      {
         throw new GISError(
            GISError::ERROR_TYPE_MINUTES,
            \sprintf( "'%s' is not of required decimal number format.", $minutes )
         );
      }

      $this->extractTime( $minutes, $seconds );

   }
46204
def s2time(secs, show_secs=True, show_fracs=True):
    """"""
    try:
        secs = float(secs)
    except:
        return "--:--:--.--"
    wholesecs = int(secs)
    centisecs = int((secs - wholesecs) * 100)
    hh = int(wholesecs / 3600)
    hd = int(hh % 24)
    mm = int((wholesecs / 60) - (hh*60))
    ss = int(wholesecs - (hh*3600) - (mm*60))
    r = "{:02d}:{:02d}".format(hd, mm)
    if show_secs:
        r += ":{:02d}".format(ss)
    if show_fracs:
        r += ".{:02d}".format(centisecs)
    return r
1320940
public function minDate($min, $msg)
    {
        if(is_numeric($min)) { // Probably an epoch.
            $min = new \DateTime('@' . $min);
        }
        else {
            $min = new \DateTime($min);
        }
        
        try {
            $dt = new \DateTime($this->_value, new \DateTimeZone("UTC"));
        }
        catch(Exception $e) {
            $this->_errors[] = $msg;
        }
        
        if($dt < $min) {
            $this->_errors[] = $msg;
        }
        
        return $this;
    }
800069
public static function secondsTo($unit, $seconds)
    {
        $method = $unit.'ToSeconds';

        return  (float) $seconds / (float) self::$method();
    }
811002
public static function formatSeconds($seconds)
    {
        $format = '';
        $rest = $seconds;
        if ($seconds >= 86400) {
            $format .= floor($seconds/86400).'d ';
            $rest = $seconds%86400;
        }

        if ($rest >= 3600) {
            $format .= floor($rest/3600).'h ';
            $rest = $rest%3600;
        }

        if ($rest >= 60) {
            $format .= floor($rest/60) . 'min ';
            $rest = $rest%60;
        }

        if ($rest > 0) {
            $format .= $rest . 'sec ';
        }

        return trim($format);
    }
241889
function formatTime($seconds) {
		switch (true) {
			case $seconds == 0:
				return 0;
			
			case $seconds < 0.01:
				$time = round($seconds * 1000, 2) . 'ms';
				break;
			
			case $seconds < 0.1:
				$time = round($seconds * 1000, 1) . 'ms';
				break;
			
			case $seconds < 1:
				$time = round($seconds * 1000) . 'ms';
				break;
			
			case $seconds < 10:
				$time = round($seconds, 2) . 's';
				break;
			
			default:
				$time = round($seconds, 1) . 's';
		}
		
		return $time;
	}