Created
June 9, 2009 11:55
-
-
Save sarahhodne/126438 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Credits to Cobi */ | |
function atime ($time) { | |
if (is_numeric($time)) return $time; | |
$ret = 0; | |
$tmp = ''; | |
for ($i = 0; $i < strlen($time); $i++) { | |
if (is_numeric($time{$i})) { | |
$tmp.= $time{$i}; | |
} else { | |
switch ($time{$i}) { | |
case 'd': $tmp *= 86400; break; | |
case 'h': $tmp *= 3600; break; | |
case 'm': $tmp *= 60; break; | |
} | |
$ret += $tmp; | |
$tmp = 0; | |
} | |
} | |
$ret += $tmp; | |
return $ret; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def atime(time) | |
return time if time.to_i.to_s == time.to_s | |
time.downcase.scan(/\d+[dhms]?/).map do |t| | |
case t[-1] | |
when ?d | |
t[0..-1].to_i * 86400 | |
when ?h | |
t[0..-1].to_i * 3600 | |
when ?m | |
t[0..-1].to_i * 60 | |
when ?s | |
t[0..-1].to_i | |
else | |
t.to_i | |
end | |
end.inject { |sum, i| sum + i }.to_s | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Credits to grawity */ | |
function atime($time) { | |
if (is_numeric($time)) return $time; | |
$ret = 0; | |
preg_match_all("/\\d+[dhms]?/", $time, $matches); | |
foreach ($matches[0] as $match) { | |
$t = intval(substr($match, 0, strlen($match) -1)); | |
switch ($match[strlen($match) - 1]) { | |
case "d": $ret += $t * 86400; break; | |
case "h": $ret += $t * 3600; break; | |
case "m": $ret += $t * 60; break; | |
case "s": $ret += $t; break; | |
default: $ret += $t; | |
} | |
} | |
return $ret; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:: Credits to grawity :: | |
@echo off & setlocal | |
set /p Input=Enter Xh Ym Zs: | |
if "%Input%"=="" goto :EOF | |
set Input=%Input: =% | |
if "%Input%"=="" goto :EOF | |
set /a Output=idx=skip=0 | |
setlocal enabledelayedexpansion | |
:next | |
set Char=!Input:~%idx%,1! | |
if "%Char%"=="" goto :end | |
if "%Char%"==" " goto :end | |
if "%Char%"=="d" set /a m=86400 & goto :act | |
if "%Char%"=="h" set /a m=3600 & goto :act | |
if "%Char%"=="m" set /a m=60 & goto :act | |
if "%Char%"=="s" set /a m=1 & goto :act | |
goto :skip | |
:act | |
set /a length=idx-skip | |
set num=!Input:~%skip%,%length%! | |
set /a Output=Output + (num * m) | |
set /a skip=idx+1 | |
:: echo !Input:~0,%skip%! = %Output%s | |
:skip | |
set /a idx=idx+1 | |
goto :next | |
:end | |
echo %Input% = %Output%s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment