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

[Bug] Incorrect regex for xs:dateTime #355

Open
mjacoby opened this issue Dec 11, 2024 · 2 comments
Open

[Bug] Incorrect regex for xs:dateTime #355

mjacoby opened this issue Dec 11, 2024 · 2 comments

Comments

@mjacoby
Copy link

mjacoby commented Dec 11, 2024

See Bug description admin-shell-io/aas-specs#498

Relevant code

timezone_frag = r"(Z|\+00:00|-00:00)"

@mristin
Copy link
Contributor

mristin commented Dec 11, 2024

Hi @mjacoby ,
This is the pattern for the date-time in UTC, an AAS-specific date time with the time zone fixed to UTC:

def matches_xs_date_time_UTC(text: str) -> bool:
"""
Check that :paramref:`text` conforms to the pattern of an ``xs:dateTime``.
The time zone must be fixed to UTC. We verify only that the ``text`` matches
a pre-defined pattern. We *do not* verify that the day of month is
correct nor do we check for leap seconds.
See: https://www.w3.org/TR/xmlschema-2/#dateTime
:param text: Text to be checked
:returns: True if the :paramref:`text` conforms to the pattern
"""
digit = "[0-9]"
year_frag = f"-?(([1-9]{digit}{digit}{digit}+)|(0{digit}{digit}{digit}))"
month_frag = f"((0[1-9])|(1[0-2]))"
day_frag = f"((0[1-9])|([12]{digit})|(3[01]))"
hour_frag = f"(([01]{digit})|(2[0-3]))"
minute_frag = f"[0-5]{digit}"
second_frag = f"([0-5]{digit})(\\.{digit}+)?"
end_of_day_frag = "24:00:00(\\.0+)?"
timezone_frag = r"(Z|\+00:00|-00:00)"
date_time_lexical_rep = (
f"{year_frag}-{month_frag}-{day_frag}"
f"T"
f"(({hour_frag}:{minute_frag}:{second_frag})|{end_of_day_frag})"
f"{timezone_frag}"
)
pattern = f"^{date_time_lexical_rep}$"
return match(pattern, text) is not None

Note the function name matches_xs_date_time_UTC. The date-time from XSD with different time zones is defined in:

def matches_xs_date_time(text: str) -> bool:

Following the issue the cause of: admin-shell-io/aas-specs#498, when you look at the relevant line in JSON schema:
https://github.com/admin-shell-io/aas-specs/blob/04a1f04b9748978767c21d765cb464249a818d2f/schemas/json/aas.json#L224

"pattern": "^-?(([1-9][0-9][0-9][0-9]+)|(0[0-9][0-9][0-9]))-((0[1-9])|(1[0-2]))-((0[1-9])|([12][0-9])|(3[01]))T(((([01][0-9])|(2[0-3])):[0-5][0-9]:([0-5][0-9])(\\.[0-9]+)?)|24:00:00(\\.0+)?)(Z|\\+00:00|-00:00)$"

, it corresponds to:

last_update: Optional["Date_time_UTC"]

so the pattern is correct (according to my understanding).

@mjacoby
Copy link
Author

mjacoby commented Dec 13, 2024

After having a closer look at things...I get what you are saying and I mostly agree.
The specification says the following for basicEventElement.lastUpdate
image

The issue here is that the Type is dateTime which is defined as xs:dateTime, meaning it can have any timezone. However, the explanation column states that the timestamp should/must(?) be in UTC. Based on that you introduced a new "type" Date_time_UTC. I would argue that the specification is wrong or at least inconsistent as the type information is constrained by the explanation to an undefined type "dateTimeUTC". The correct way to handle this would be to change the specification to either defined the type dateTimeUTC or to remove the UTC restriction in the explanation.

If you code is correct or not kinda depends on the interpretation of the specification because the type info says that it can contain any timezone but the explanation says it cannot.

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

No branches or pull requests

2 participants