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

Feature request: Asterisk in WMIDateTime support #107

Open
ThalusA opened this issue Jan 28, 2025 · 6 comments
Open

Feature request: Asterisk in WMIDateTime support #107

ThalusA opened this issue Jan 28, 2025 · 6 comments
Labels
enhancement New feature or request

Comments

@ThalusA
Copy link

ThalusA commented Jan 28, 2025

Hi, based on the WMI specification https://learn.microsoft.com/en-us/windows/win32/wmisdk/cim-datetime, datetime can use asterisk for unspecified value, would it be possible to treat them as 0 or maybe add something that can handle that ? As of right now it can't handle that.

@ohadravid
Copy link
Owner

Hi @ThalusA 👋

Can you provide a failing example?

I think it should be possible to support this by adding new enums which can represent the * patterns and defer to the regular deser code otherwise (https://github.com/ohadravid/wmi-rs/blob/main/src/datetime.rs#L13 / https://github.com/ohadravid/wmi-rs/blob/main/src/datetime_time.rs#L17), but that will depend on the exact usecase.

@ThalusA
Copy link
Author

ThalusA commented Jan 28, 2025

The failing example is 20210601114102.**********

@ohadravid
Copy link
Owner

Can you give an example where you are using this pattern?

@ThalusA
Copy link
Author

ThalusA commented Jan 28, 2025

A proprietary software I use that return to me those values, and based on the WMI specification it tells me that it should be accepted as a valid value.

@ohadravid
Copy link
Owner

ohadravid commented Jan 28, 2025

Reading the spec, I think it might be hard even to represent the simpler "range" variant (the "April 1st any year" example seems complex and doesn't have any Rust analog I can think of).

Since even the timezone can be optional, something like WMIDateTimeRange { start: NaiveDateTime, span: ..., tz: Option<FixedOffset> } is a bit strange, and is anyway limited to only asterisks-in-postfix.

Since your example doesn't seem to be valid according to the spec (there should be a +*** at the end for the timezone), I think the best way would be for you to write your own struct WMIDateTimeWithAsterisks(pub DateTime<FixedOffset>) and implement parse as you wish.

If you think the impl is general enough, I'd be happy to accept a PR 😄

@ThalusA
Copy link
Author

ThalusA commented Jan 29, 2025

Understandable, I thought the same thing but I wasn't 100% sure. I might make a PR if I have time in my time-off, for now I just implemented a function to act as the deserializer that deserialize as a string, replace asterisks to zero and then parse it as WMIDateTime

@ohadravid ohadravid added the enhancement New feature or request label Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants