jq icon indicating copy to clipboard operation
jq copied to clipboard

RFE: Implement date parsing and formatting on Windows just as on other platforms

Open Alanscut opened this issue 5 years ago • 10 comments

The parameter strptime of jq-win64_1.6.exe does not work properly. for example:

windows-64:

# echo '"2015-03-05T23:51:47Z"' | ./jq-win64_1.6.exe 'strptime("%Y-%m-%dT%H:%M:%SZ")'
jq: error (at <stdin>:1): strptime/1 not implemented on this platform

# echo '"2015-03-05T23:51:47Z"' | ./jq-win64_1.6.exe 'fromdate'
jq: error (at <stdin>:1): strptime/1 not implemented on this platform


unbutu:
root@oss-001:test_jq#  echo '"2015-03-05T23:51:47Z"' | jq 'strptime("%Y-%m-%dT%H:%M:%SZ")'
[
  2015,
  2,
  5,
  23,
  51,
  47,
  4,
  63
]
root@oss-001:test_jq#  echo '"2015-03-05T23:51:47Z"'| jq 'fromdate'
1425599507


Alanscut avatar Feb 27 '20 06:02 Alanscut

Same issue for me when using jq's fromdateiso8601 function on Windows 10 build 19042.631.

matijasx avatar Aug 17 '21 00:08 matijasx

Same issue for me when using jq's fromdateiso8601 function on Windows 10 build 19045.2486,

MarkSte avatar Feb 04 '23 17:02 MarkSte

same issue for me when using jq's fromdateiso8601 function on windows server 2016.

Pradeep-Lokhande avatar Jun 29 '23 10:06 Pradeep-Lokhande

same issue for me when using jq's fromdateiso8601 function on windows 11

alikzalikz avatar Jul 19 '23 11:07 alikzalikz

I see that the recent jq-1.8.0 release added #3008, #3094, #3071, and the release notes say:

  • Provide strptime/1 on all systems. @george-hopkins @fdellwing https://github.com/jqlang/jq/pull/3008 https://github.com/jqlang/jq/pull/3094
  • Fix _WIN32 port of strptime. @emanuele6 https://github.com/jqlang/jq/pull/3071

but I'm guessing that this particular ticket #2071 isn't quite complete yet. I've tried both the -amd64 and the -i386 builds, in case those #ifdef WIN32 actually are specific to the 32-bit build, and I'm still getting strptime/1 only supports ISO 8601 on this platform:

With Windows 11, git-bash (my normal setup):

$ echo '{"date": "2025-05-01T00:00:00Z"}' | jq '.date | strptime("%F")'
jq: error (at <stdin>:1): strptime/1 only supports ISO 8601 on this platform

With Windows 11 cmd window (not my normal setup, so I may be typing this incorrectly), I get:

$ echo '{"date": "2025-05-01T00:00:00Z"}' | jq '.date | strptime("%F")'
'strptime' is not recognized as an internal or external command,
operable program or batch file.

$ echo '{"date": "2025-05-01T00:00:00Z"}' | jq-windows-i386.exe '.date | strptime("%F")'
'strptime' is not recognized as an internal or external command,
operable program or batch file.
$ jq --version
jq-1.8.0

$ jq-windows-i386.exe --version
jq-1.8.0

Ultimately, what I'm looking for is for this to work on Windows as it does on my Mac (even in 1.7.1):

$ echo '{"date": "August 5, 1975"}' | jq '.date | strptime("%B %d, %Y")'

eli-hu avatar Jun 02 '25 22:06 eli-hu

The error message comes from 0fc8200ab42ea2b629fa0852987cfd4f6346b2dc, which implemented strptime fallback using sscanf. After that, fdab39bc7b8d41c1ae410f03a42afc10a9322c99 included strptime from NetBSD. So I think we can drop the #ifdef in f_strptime but am I correct? Also we have to include the license in COPYING. CC: @wader

itchyny avatar Jun 03 '25 23:06 itchyny

I think we came to a similar conclusion in the issue millisecond parsing https://github.com/jqlang/jq/issues/1409

wader avatar Jun 05 '25 17:06 wader

@eli-hu @Alanscut Could you test the executable built here?

itchyny avatar Jun 07 '25 11:06 itchyny

Is there any Windows user able to test the executable as above comment?

itchyny avatar Jun 10 '25 03:06 itchyny

I've mostly used wine to test windows binaries but it feels a bit shaky to use to testing time stuff maybe? The other alternative might be windows dev ISO images from microsoft https://developer.microsoft.com/en-us/windows/downloads/virtual-machines/ but they are giant and in my experience slow to use for development.

wader avatar Jun 10 '25 08:06 wader