Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Declined Date and time formats vs. @MAKEAGE and other date-time functions

May
3,515
5
1/ Allow @MAKEAGE (and possibly all other relevant functions and commands)
to accept a date and time combination in the form of %_datetime. Retrieving
%_date and %_time from the OS separately could result in mismatched values
if you do it too close to midnight. While the chance of it happening is low,
sooner or later someone somewhere will be bitten by it, but using %_datetime
avoids the problem.

2/ Allow functions and commands which accept a time of day as a parameter
(or as a part of a parameter) would have an optional extra parameter to
specify that the time parameter in the current function (command) invocation
is 12-hour or 24-hour time, instead of the default.

3/ Enhance the optional format specifier of @AGEDATE. and add one to
@MAKETIME to control time formatting: 12h vs. 24h, am vs. AM, etc.

--
Steve
 
Steve Fábián wrote:


> 2/ Allow functions and commands which accept a time of day as a parameter
> (or as a part of a parameter) would have an optional extra parameter to
> specify that the time parameter in the current function (command) invocation
> is 12-hour or 24-hour time, instead of the default.
>
> 3/ Enhance the optional format specifier of @AGEDATE. and add one to
> @MAKETIME to control time formatting: 12h vs. 24h, am vs. AM, etc.

There is no chance we will ever add 12-hour time formats to any of those
functions. It would add considerable complication (and confusion) and
offer no additional functionality.

Rex Conn
JP Software
 
rconn wrote:
| Steve Fábián wrote:
| ---Quote---
|| 2/ Allow functions and commands which accept a time of day as a
|| parameter (or as a part of a parameter) would have an optional extra
|| parameter to specify that the time parameter in the current function
|| (command) invocation is 12-hour or 24-hour time, instead of the
|| default.
||
|| 3/ Enhance the optional format specifier of @AGEDATE. and add one to
|| @MAKETIME to control time formatting: 12h vs. 24h, am vs. AM, etc.
| ---End Quote---
| There is no chance we will ever add 12-hour time formats to any of
| those functions. It would add considerable complication (and
| confusion) and
| offer no additional functionality.

I do not use 12-hour format for any of my work. However, I have lots of
incoming data which uses it, and I need to convert it before use. If at
least one function did the conversion, I'd not have to use a batch program
for the purpose.
--
Steve
 
I do not use 12-hour format for any of my work. However, I have lots of
incoming data which uses it, and I need to convert it before use. If at
least one function did the conversion, I'd not have to use a batch program
for the purpose.


I have exactly one batch file where I need to make this conversion so I haven't coded it into a function, but it easily could be.

Here's my code:
Code:
set schdt=%@iniread["\[I]somewhere[/I]\Settings.ini",manager,nextdownload]
Rem  The value of the nextdownload item looks like "2005-Jan-27,02:25pm"
set schtime=%@word["%=c",1,%schdt]
set scht=%@maketime[%@eval[%@time[%@replace[12:,00:,%schtime]] + %@if[%@index[%schtime,p] ge 0,%@time[12],0]]]


Since @time accepts a string like "12:34pm" and just uses the "12:34", this works.
 
dcantor wrote:
| I have exactly one batch file where I need to make this conversion so
| I haven't coded it into a function, but it easily could be.
|
| Here's my code:
|
| Code:
| ---------
| set schdt=%@iniread["\somewhere\Settings.ini",manager,nextdownload]
| Rem The value of the nextdownload item looks like
| "2005-Jan-27,02:25pm"
| set schtime=%@word["%=c",1,%schdt]
| set scht=%@maketime[%@eval[%@time[%@replace[12:,00:,%schtime]] +
| %@if[%@index[%schtime,p] ge 0,%@time[12],0]]] ---------
|
| Since @time accepts a string like "12:34pm" and just uses the
| "12:34", this works.

I like your algorithm. To improve performance, I'd replace %@time[12] with
43200. In your circumstances, undoubtedly it performs perfectly.

However, it has minor problems, which show up in the various places I need
to use the conversion.
1/ If the time format includes seconds, and the minutes field is 12, the
minutes are also changed.
2/ You need to know in advance what the time field separator is. Not all
countries use colon.
3/ Fails if the AM/PM indication is before the numeric part.

I have written some UDFs, which actually run a batch program to obtain their
result. Typically they look like this:

function xyz=`%@execstr[xyz.btm %*]`

and xyz.btm returns its result with an ECHO command. BTW, such batch files
are prime candidates for the batch compiler! I may need to do this for the
instant problem...
--
Steve
 
Steve Fábián wrote:
| dcantor wrote:
|| I have exactly one batch file where I need to make this conversion so
|| I haven't coded it into a function, but it easily could be.
||
|| Here's my code:
||
|| Code:
|| ---------
|| set schdt=%@iniread["\somewhere\Settings.ini",manager,nextdownload]
|| Rem The value of the nextdownload item looks like
|| "2005-Jan-27,02:25pm"
|| set schtime=%@word["%=c",1,%schdt]
|| set scht=%@maketime[%@eval[%@time[%@replace[12:,00:,%schtime]] +
|| %@if[%@index[%schtime,p] ge 0,%@time[12],0]]] ---------
||
|| Since @time accepts a string like "12:34pm" and just uses the
|| "12:34", this works.
|
| I like your algorithm. To improve performance, I'd replace %@time[12]
| with 43200. In your circumstances, undoubtedly it performs perfectly.
|
| However, it has minor problems, which show up in the various places I
| need to use the conversion.
| 1/ If the time format includes seconds, and the minutes field is 12,
| the minutes are also changed.
| 2/ You need to know in advance what the time field separator is. Not
| all countries use colon.
| 3/ Fails if the AM/PM indication is before the numeric part.

The function below solves 1/ and 2/ above (allowed field separators are
colon :, period ., hyphen - and slash / - replace the separator list in the
@word function for other characters), and allows whitespace between the TOD
and the AM/PM indicator (when the parameter character is the ampersand & -
use %$ instead if you use TCC default):

function ampmto24=`%@maketime[ %@eval[ %@time[%@strip[ampAMP,%1]] -
%@if[%@word[":.-/",0,%1] EQ 12,43200,0] + %@if[%@index[%&,p] GE
0,43200,0] ] ]`

(all on one line, of course).
--
Steve
 
dcantor wrote:
| I have exactly one batch file where I need to make this conversion so
| I haven't coded it into a function, but it easily could be.
|
However, it has minor problems, which show up in the various places I need
to use the conversion.
...
2/ You need to know in advance what the time field separator is. Not all
countries use colon.
set sep=%@left[1,%@strip[0,%@maketime[0]]]

1/ If the time format includes seconds, and the minutes field is 12, the
minutes are also changed.
... %@strip[\,%@replace[\00%sep,\12%sep, %intime]]
will not affect minutes eq 00. Can't use \ as separator, though. If it is, choose another character like maybe @char[1].
3/ Fails if the AM/PM indication is before the numeric part.
Remove all the letters with @strip and leading spaces with @trim
... %@trim[%@strip[ampAMP,%intime]]

(But this won't fix "A.M. 12:34")

I have written some UDFs, which actually run a batch program to obtain their
result. Typically they look like this:

function xyz=`%@execstr[xyz.btm %*]`

and xyz.btm returns its result with an ECHO command.
Yup. I have some of those, too.
 
Here's my solution as a .BTM file.

It relies on the fact that neither space nor a period is a valid separator in the time argument to @TIME. Because of that, the period can be used as an anchor at the left of the hours.

Code:
@echo off
rem  Input can be hours only hh:mm or hh:mm:ss.  A.m./p.m. can be preceding, following, with
rem    or without periods, and with or without spaces.

set sep=%@left[1,%@strip[0,%@maketime[0]]]
rem    Time cannot use period or space as separator
set timestr=%@trim[%@strip[.amp,%@lower[%$]]]
set pmadd=%@if[%@index["%$",p] gt 0,43200,0]
iff %@word["%sep",0,%timestr] eq 12 then
  rem  Need to use time verbatim if there is no 'a' or 'p'.
  if %@index[%@replace[a,p,%@lower[%$]],p] eq -1 set pmadd=43200
 endiff

echo %@maketime[%@eval[%@time[%@right[-1,%@replace[.12%sep,.00%sep,.%timestr]]] + %pmadd]]
unset /q sep timestr pmadd
quit

If neither 'a.m.' nor 'p.m.' (upper or lower, periods or not) is given, then the time is taken literally; i.e., 17:34 --> 17:34, and 11:11 --> 11:11. If the hour is 12, the adjustment is made to declare it p.m.
 

Similar threads

Back
Top