-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhhmmss.min.cmd
222 lines (186 loc) · 8.03 KB
/
hhmmss.min.cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
:: By JaCk | Release 12/11/2017 | https://github.com/1ijack/BatchMajeek/blob/master/hhmmss.min.cmd | hhmmss.min.cmd --- send time(s) in seconds as params and it will return HH:MM:SS notation back
:::
::: The zlib/libpng License -- https://opensource.org/licenses/Zlib
:: Copyright (c) 2018 JaCk
::
:: This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
::
:: Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
::
:: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
::
:: 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
::
:: 3. This notice may not be removed or altered from any source distribution.
:::
:: works with/without DelayedExpansion - Still need Extensions (for label calls, errorlevels, param features)
@echo off & setlocal EnableExtensions
::: User Vars
rem Set to "true" when you want to print both values, orig secs, and new format
rem Set to "" when you want to print only new format
set "hm2_print_secs_and_hhmmss="
:::::::::::::::::::::::::::::::::::::::
::: do not modify below :::
:::::::::::::::::::::::::::::::::::::::
rem No question about it, it's one o'them nasty "question-marks". Swap it out, stat.
if "%~1%~2%~3%~4%~5" equ "" (
set "hms_pargs=/h"
) else set "hms_pargs=%*"
set "hms_pargs=%hms_pargs:?=[_mp0qm_]%"
:::::::::::::::::: ::::::::::::::::::
:: ::
:: Stario-gooooo ::
:: ::
:: zoom zooosh zaaam, zreeech. vrooo ::
:: ::
::::::::::: ::::::::::::: :::::::::::
::: Starting PVAR ArgFeeder ~~ L4G: Halp mae gnougn, pl9xyz
for %%Z in (
%hms_pargs%
) do for /f "tokens=* delims=-/" %%V in (
"/%%Z"
) do call :func_hms_args "%%~V"
:::::::::::::::::: ::::::::::::::::::
:: ::
:: -- fin-laundia -- ::
:: "End" ::
:: too fast? Isn't that a good thing ::
:: ::
::::::::::: ::::::::::::: :::::::::::
set "help_cntr="
goto :eof
:::::::::::::::::: :::::::::::::::::::
:: ::
:: Bunctions ::
:: ::
:: [ --- ----- >x< ----- --- ] ::
:::::::::::::::::: ::::::::::::::::::
goto :eof
:: Usage :: func_hms_args arg
rem Speed-argumentor, scrubs input, looking for help, blanks, unknowns, and integers to process
rem No Issues -- errorlevel 0
rem When Unknown argument -- errorlevel is 1
:func_hms_args
rem Unfilter filtered
set "args_parg=%~1"
set "args_parg=%args_parg:[_mp0qm_]=?%"
rem Are you prefixed with a zero? if so, bad int, bad. Back to the end of the line.
if "%args_parg:~0,1%" equ "0" if "%args_parg:~1,1%" neq "" (
call %~0 "%args_parg:~1%"
goto :func_args_lower_intestine
)
rem are you literally zero? ok, we'll run 'er through. Don't be suprised if its 00:00:00
if "1%~1" equ "10" (
call :func_hms_minimain_lilscheeph "hms_t" "%~1"
goto :func_args_lower_intestine
)
rem Checq for halps
for %%H in ("[_mp0qm_]"; "h"; "help") do if "/%%~H" equ "/%~1" (
call :func_hms_halp_mae
goto :func_args_lower_intestine
) 2>nul
rem are you a blank?
if "1%args_parg%" equ "1[_mp0qm_]=?" (
call :func_hms_halp_mae
goto :func_args_lower_intestine
)
rem are you an int? finally, lets do this
set /a "nargs_parg=((%args_parg% -1)/1) +1"
if "%nargs_parg%" gtr "0" (
call :func_hms_minimain_lilscheeph "hms_t" "%nargs_parg%"
goto :func_args_lower_intestine
)
set "nargs_parg="
rem heck, I dont know what you is... sorry bub
call :func_hms_halp_mae 2>nul
( echo/&echo/&echo/&echo/Error: %~nx0: Unrecognized Argument "%args_parg%"
echo/&echo/
) 1>&2
call :func_args_lower_intestine
exit /b 1
rem :: Usage :: func_args_lower_intestine
rem undefines args vars
:func_args_lower_intestine
set "args_parg="
set "nargs_parg="
goto :eof
goto :eof
:: Usage :: func_hms_get_time_from_secs returnVar sendTime
rem Converts from secs to HH:MM:SS notation
rem Note: param2-sendTime -- Integer value: ammount of secs [Limit: 2147483647] [HumanReadable: 2,147,483,647]
rem Note: param1-returnVar -- Returns param1 as HH:MM:SS
rem Note: Checks input for integer, when encountering errors sets returnVar to 00:00:00 and sets ErrLvl to 101
rem Example:
rem func "varDuration" "6430"
:func_hms_get_time_from_secs
if "%~1" equ "" exit /b 101
set "%~1=00:00:00"
if "%~2" equ "" exit /b 101
rem verify - valid positive int
set /a "%~1=%~2 * 1" 2>nul
if not errorlevel 0 set "%~1=00:00:00" & exit /b 101
set "%~1=00:00:00"
if not %~2 gtr 0 exit /b 101
rem cheap, quick, and dirty -- fire and forget
set "%~1=00:00:%~2"
if %~2 lss 10 set "%~1=00:00:0%~2"
if %~2 lss 60 exit /b 0
set "%~1=00:00:00" rem reset -- just for [en]sanity
rem not as cheap, but still quick, and dirty(4) -- calc(1), strip(3) padded(2) zeros
2>nul set /a "hms_s2t_h=%~2/3600"
2>nul set /a "hms_s2t_m=(%~2 - (%hms_s2t_h% * 3600))/60"
2>nul set /a "hms_s2t_s=(%~2 - (%hms_s2t_m% * 60) - (%hms_s2t_h% * 3600))"
set "hms_s2t_m=00%hms_s2t_m%"
set "hms_s2t_s=00%hms_s2t_s%"
set "%~1=%hms_s2t_h%:%hms_s2t_m:~-2%:%hms_s2t_s:~-2%"
if %hms_s2t_h% lss 10 set "%~1=0%hms_s2t_h%:%hms_s2t_m:~-2%:%hms_s2t_s:~-2%"
if %hms_s2t_h% equ 0 set "%~1=00:%hms_s2t_m:~-2%:%hms_s2t_s:~-2%"
rem man, good thing I still have some time to clean this up
set "hms_s2t_h="
set "hms_s2t_m="
set "hms_s2t_s="
if defined %~1 exit /b 0
rem this should never happen, but you never know
set "%~1=00:00:00" & exit /b 101
goto :eof
:: Usage :: func_hms_halp_mae
rem desp-lae halps to phresh-StSt-StAHN-DERD--aowette
:func_hms_halp_mae
if defined help_cntr goto :eof
set /a "help_cntr+=1"
echo/
echo/help: %~nx0, Converts Secs to Expanded Time HH:MM:SS.MS
echo/ Usage: %~nx0 [ --help^| secs ] [secs2] [etc]
echo/
echo/ Input Examples:
echo/ %~nx0 --help
echo/ %~nx0 61
echo/ %~nx0 152320 51358
echo/
echo/ Examples: Input Cmd ~^> Result
echo/ %~nx0 65 ~^> 00:01:05
echo/ %~nx0 1066 ~^> 00:17:46
goto :eof
:: Usage :: func_hms_minimain_lilscheeph ReturnVar sendTime-Seconds
rem Sub-Process control -- Help faciliate improvements and help with DelayedExpansion being disabled
:func_hms_minimain_lilscheeph
if "%~2" equ "" goto :eof
if "%~1" equ "" goto :eof
call :func_hms_get_time_from_secs "%~1" "%~2"
if defined hm2_print_secs_and_hhmmss call :func_hms_MisterDank_AB_reporter "%~1" "%~2"
if not defined hm2_print_secs_and_hhmmss call :func_hms_MisterDank_AB_reporter "%~1"
set "%~1="
goto :eof
:: Usage :: func_hms_MisterDank_AB_reporter "varName" "timeInSeconds-Optional"
rem Writes to StndOut
rem Note: Param1 "varName" -- This is the varLabel/Name (not the value)
rem Note: Param2 "timeInSeconds-Optional" -- Original Secs value
:func_hms_MisterDank_AB_reporter
if "%~1" equ "" ( exit /b 101 ) else if not defined %~1 exit /b 101
if "%~2" equ "" ( call echo/%%%~1%%
) else call echo/%~2 ^*%%%~1%%
goto :eof
if "%~2" equ "" for /f "tokens=2 delims==" %%C in ('set %~1') do echo/%%~C
if "%~2" equ "" goto :eof
for /f "tokens=2 delims==" %%C in ('set %~1') do echo/%~2 ^*%%~C
goto :eof