jTimestamp.bat date/time utility v2.1 - Replacement for getTimestamp.bat

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
war59312
Posts: 10
Joined: 07 Feb 2017 20:17
Location: U.S.A
Contact:

Re: jTimestamp.bat date/time utility - Replacement for getTimestamp.bat

#16 Post by war59312 » 10 Feb 2017 08:28

Whoops, I'm blind.

Thank you. :)

Edit: Well, still off by 1 second often:

Code: Select all

REM Get Script Start Time Using jTimestamp.cmd
CALL jTimestamp -f {ums} -r t1

REM Fancy Time Stamp
for /F "tokens=*" %%a in (
   'jTimestamp -d %t1% /F " {WKD} {MTH} {D}, {yyyy} {H12}:{NN}:{SS}{PM}"'
) do (
   
   set Timestamp=%%a   
)

set "Timestamp=%Timestamp::00am=am%"
set "Timestamp=%Timestamp::00pm=pm%"
echo %Timestamp%

REM Get Script End Time Using jTimestamp.cmd
CALL jTimestamp -f {ums} -r t2

REM Fancy Time Stamp
for /F "tokens=*" %%a in (
   'jTimestamp -d %t2% /F " {WKD} {MTH} {D}, {yyyy} {H12}:{NN}:{SS}{PM}"'
) do (
   
   set Timestamp=%%a   
)

set "Timestamp=%Timestamp::00am=am%"
set "Timestamp=%Timestamp::00pm=pm%"
echo %Timestamp%

CALL jTimestamp -d %t2%-%t1% -f " {ud} Days {h} Hours {n} Minutes And {s} Seconds" -u
ECHO.
BTW without the "-u" it shows 19 hours. Bug?

Edit 2: BTW using "-c "OUS=-1"" does not work either since its not always off.

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: jTimestamp.bat date/time utility v2.1 - Replacement for getTimestamp.bat

#17 Post by dbenham » 16 Jan 2018 22:26

I got a private message from user asun reporting a nasty bug with ISO 8601 week date computation
asun wrote: Hi Dave,

I was looking for a DOS batch function that will give me the date of a given week number and day and your JTimestamp.bat is just what I need! Thank you for writing and posting this code.
However, it's my luck that I immediately stumbled upon what appears to be a bug but I don't have the knowledge to fix it. It outputs a totally wrong date for 2018 Week 8 Day 3 (Wed) and 2018 Week 9 Day 3 (Wed) which correspond to the last two weeks of February:

% JTimestamp -D "ISO 2018-W07-3"
2018-02-14T00:00:00.000-05:00

% JTimestamp -D "ISO 2018-W08-3"
2017-12-27T00:00:00.000-05:00

% JTimestamp -D "ISO 2018-W09-3"
2017-12-27T00:00:00.000-05:00

% JTimestamp -D "ISO 2018-W10-3"
2018-03-07T00:00:00.000-05:00

As you can see, Week 7 and Week 10 worked fine but Weeks 8 and 9 returned a 2017 date. I guess the 28-day February somehow screwed this up. Could you kindly look into this to see if you could fix this bug? Much appreciated.
Thanks for reporting the bug asun.

It turns out the computation always failed if the week is 08 or 09 because I forgot to specify the base when I parsed the integer value. So the parseInt() function was seeing the leading 0 as an octal indicator, and the invalid octal values of 8 and 9 were somehow interpreted as 0. I checked, and all other parseInt() usage properly specified base 10.

So here is v2.1 that fixes the bug:
jTimestamp2.1.zip
(10.21 KiB) Downloaded 681 times

Dave Benham

asun
Posts: 1
Joined: 16 Jan 2018 19:05

Re: jTimestamp.bat date/time utility v2.1 - Replacement for getTimestamp.bat

#18 Post by asun » 17 Jan 2018 09:41

Thanks for the lightning-fast response Dave. Very much appreciated. I could be staring at the code for weeks and still wouldn't figure out this base 10 thing.
I have downloaded and tested v2.1 and everything works fine. Thanks again for creating and sharing this very useful program. - Andy

MG_0720
Posts: 1
Joined: 08 Jul 2019 06:17

Re: jTimestamp.bat date/time utility v2.1 - Replacement for getTimestamp.bat

#19 Post by MG_0720 » 08 Jul 2019 06:20

Is there any way to get the actual week number of the year to be output or set in variable for further reference?
as a TV broadcast company we need that week number out the 52 weeks?

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

Re: jTimestamp.bat date/time utility v2.1 - Replacement for getTimestamp.bat

#20 Post by penpen » 08 Jul 2019 11:14

You could use a "for/f"-loop to store that value into an environment variable:

Code: Select all

@echo off
setlocal enableExtensions disableDelayedExpansion
for /f %%a in ('jTimestamp /F "{ISOWK}"') do set "isoWk=%%~a"
set isoWk
goto :eof
Sidenote: You should be aware, that some years have 53 weeks (more specific: every year starting on thursday).


penpen

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: jTimestamp.bat date/time utility v2.1 - Replacement for getTimestamp.bat

#21 Post by dbenham » 11 Jul 2019 11:02

MG_0720 wrote:
08 Jul 2019 06:20
Is there any way to get the actual week number of the year to be output or set in variable for further reference?
as a TV broadcast company we need that week number out the 52 weeks?
Everything is fully documented in the built in help: JTIMESTAMP /?
or JTIMESTAMP /?? for paged help

If you want the result in a variable then simply use the -R option:

Code: Select all

   -R ReturnVariable

      Save the timestamp in ReturnVariable instead of displaying it.
      ReturnVariable is unchanged if an error occurs.
      Default is empty, meaning write to stdout.


The week number may be easily gotten, depending on which week numbering system you use. jTimestamp uses the ISO 8601 standard, where week 1 includes the first Thursday of the calendar year, and weeks start with Monday = 1.

The following week formats are available for use with the -F (format) option:

Code: Select all

{ISOWY}  yyyy
         ISO 8601 week numbering year
         Dec 29, 30, or 31 may belong to the next Jan year
         Jan 01, 02, or 03 may belong to the prior Dec year

{ISOWK}  ww
         ISO 8601 week number
         Week 01 is the week with the year's first Thursday

{ISOWD}  d
         ISO 8601 day of week: 1=Monday, 7=Sunday

{ISODTW} yyyyWwwd
         Compressed ISO 8601 week date format

{ISO-DTW} yyyy-Www-d
         ISO 8601 week date format


Dave Benham

NVMedia
Posts: 3
Joined: 28 Dec 2020 05:54

Re: jTimestamp.bat date/time utility v2.1 - Replacement for getTimestamp.bat

#22 Post by NVMedia » 28 Dec 2020 05:57

This year the DOW is off by one. It returned as week 53 for the week of 12/28/20 when it is truly wk 01.
this will probably throw off the rest of the year - how can we correct or adjust this?

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

Re: jTimestamp.bat date/time utility v2.1 - Replacement for getTimestamp.bat

#23 Post by penpen » 28 Dec 2020 10:54

The above script uses ISO 8601, which defines the week 01 as that week which contains the first Thursday in January.
Therefore it is correct to return 53 for the week of 12/28/20, because this weeks Thursday is on 12/31/2020.


penpen

NVMedia
Posts: 3
Joined: 28 Dec 2020 05:54

Re: jTimestamp.bat date/time utility v2.1 - Replacement for getTimestamp.bat

#24 Post by NVMedia » 05 Jan 2021 07:52

ok.. this is why I also asked if there was a way to adjust it.
Can we change wk 01 to be the first MONDAY?

NVMedia
Posts: 3
Joined: 28 Dec 2020 05:54

Re: jTimestamp.bat date/time utility v2.1 - Replacement for getTimestamp.bat

#25 Post by NVMedia » 05 Jan 2021 08:00

actually the better day would be FRI or SAT. (if it can be changed from Thursday)
we use for broadcasting script based on a 52 week calendar year.
this calendar: https://www.rab.com/public/reports/2020-2021.pdf

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: jTimestamp.bat date/time utility v2.1 - Replacement for getTimestamp.bat

#26 Post by dbenham » 05 Jan 2021 17:22

Currently there is no option to use a different week definition - only ISO 8601 is supported.

I considered trying to support additional standards, but opted not to do so. The math should not be too hard, but establishing a sensible/workable set of options and display syntax just became a bit overwhelming, especially when I didn't know if anyone would use it.

I might revisit this in the future, but no promises.


Dave Benham

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

Re: jTimestamp.bat date/time utility v2.1 - Replacement for getTimestamp.bat

#27 Post by penpen » 05 Jan 2021 19:20

NVMedia wrote:
05 Jan 2021 07:52
ok.. this is why I also asked if there was a way to adjust it.
Can we change wk 01 to be the first MONDAY?
I like to add, that whatever day you choose, you run into the same issue (just with another day and in different years):
If the 12/31/yyyy happens to be a MONDAY, than a script that defines it by a Monday will say it's week 53 (because there are more than 52*7=364 days in a year).

So it is essentially for you to find out which day is used by your broadcasting script (guessing that it's monday is not a good option - in case you didn't guess but already have looked that up: Sorry, but i wanted to be sure).
Also in case that broadcasting script does something different to compute the week number, you should do the same in your batch.
Also if possible add a big note in both scripts (broadcasting script and your batch file), that whoever might change that in one script also must change that in the other.


penpen

Post Reply