Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String was not recognized as a valid DateTime #24

Closed
ba31 opened this issue Apr 27, 2023 · 2 comments · Fixed by #28
Closed

String was not recognized as a valid DateTime #24

ba31 opened this issue Apr 27, 2023 · 2 comments · Fixed by #28

Comments

@ba31
Copy link

ba31 commented Apr 27, 2023

SUMMARY

Data Example format does not work with value "2019-09-07T15:50:00+00"

ISSUE TYPE
PS C:\Windows\System32\WindowsPowerShell\v1.0> $dt = '2019-09-07T15:50:00+00'
$dtVal = [DateTimeOffset]::ParseExact(
    $dt,
    [string[]]@("yyyy-MM-dd'T'HH:mm:ss.FFFFFFFK"),
    [System.Globalization.CultureInfo]::InvariantCulture,
    [System.Globalization.DateTimeStyles]::AssumeUniversal)
$dtVal.UtcDateTime.ToFileTimeUtc()
Exception calling "ParseExact" with "4" argument(s): "String was not recognized as a valid DateTime."
At line:2 char:1
+ $dtVal = [DateTimeOffset]::ParseExact(
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : FormatException
 
132123450000000000

PS C:\Windows\System32\WindowsPowerShell\v1.0> 

COMPONENT NAME

microsoft.ad.user

ANSIBLE VERSION
ansible [core 2.13.9]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/demo/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/demo/.local/lib/python3.8/site-packages/ansible
  ansible collection location = /home/demo/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.8.10 (default, Nov 14 2022, 12:59:47) [GCC 9.4.0]
  jinja version = 3.1.2
  libyaml = True
COLLECTION VERSION
Collection        Version
----------------- -------
community.general 6.6.0

OS / ENVIRONMENT

Linux 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

STEPS TO REPRODUCE
- microsoft.ad.user:
    name: MyUser
    state: present
    attributes:
      set:
        accountExpires:
          type: date_time
          value: '2019-09-07T15:50:00+00'

ansible-playbook -i hosts microsoft.ad.user.yaml

EXPECTED RESULTS

It should not generate "String was not recognized as a valid DateTime." and should set the expiry time

ACTUAL RESULTS

"msg": "Unhandled exception while executing module: Exception calling \"ParseExact\" with \"4\" argument(s): \"String was not recognized as a valid DateTime.\""

@jborean93
Copy link
Collaborator

You need to use the TZ offset in the format HH:MM or HHMM and not just HH.

[DateTimeOffset]::ParseExact(
    '2019-09-07T15:50:00+0000',
    [string[]]@("yyyy-MM-dd'T'HH:mm:ss.FFFFFFFK"),
    [System.Globalization.CultureInfo]::InvariantCulture,
    [System.Globalization.DateTimeStyles]::AssumeUniversal)

[DateTimeOffset]::ParseExact(
    '2019-09-07T15:50:00+00:00',
    [string[]]@("yyyy-MM-dd'T'HH:mm:ss.FFFFFFFK"),
    [System.Globalization.CultureInfo]::InvariantCulture,
    [System.Globalization.DateTimeStyles]::AssumeUniversal)

The K datetime identifier is better described at https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings#KSpecifier.

Are there docs that give you the format +00 without the minute offset? If so we need to fix those.

@jborean93
Copy link
Collaborator

jborean93 commented May 1, 2023

I believe I found the incorrect example and have fixed it with #28. If you do notice any others please open an issue or PR with the details so we can fix them.

Thanks for reporting this and the other issues you came across.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants