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

Parse VolumeDateDescriptor as datetime object #97

Open
rlaphoenix opened this issue Jun 30, 2022 · 0 comments
Open

Parse VolumeDateDescriptor as datetime object #97

rlaphoenix opened this issue Jun 30, 2022 · 0 comments

Comments

@rlaphoenix
Copy link
Contributor

rlaphoenix commented Jun 30, 2022

Is it possible at all that you could rework the VolumeDateDescriptor class as a class inheriting a datetime object, with the initialization overridden to parse ISO9660 dates?

def date_convert(vdd: VolumeDescriptorDate) -> Optional[datetime]:
    if not vdd.year:
        return None
    return datetime(
        year=vdd.year, month=vdd.month, day=vdd.dayofmonth,
        hour=vdd.hour, minute=vdd.minute, second=vdd.second,
        microsecond=vdd.hundredthsofsecond,  # TODO: Is this really microseconds?
        # offset the timezone, since ISO's dates are offsets of GMT in 15 minute intervals, we
        # need to calculate that but in seconds to pass to `tzoffset`.
        tzinfo=tzoffset("GMT", (15 * vdd.gmtoffset) * 60)
    )

Right now I'm having to do the above to deal with converting every specific VDD to make them useful in scenarios where you want to read it in context for printing or working with timedelta's or other modifications.

The only thing I'm unsure about in terms of the conversion code I made above, is the hundrethsofsecond. I believe it's a centisecond, therefore, I believe I need to multiply the value by 10,000 to get it as a microsecond but I'm unsure.

The reason I ask for this change is I use the PVD by printing all of its data under a repr(). This results in FileOrTextIdentifier and VolumeDescriptorDate printing in an effectively unusable manner. Even if I str() it's not much different if at all. My solution is to just v = v.text on FileOrTextIdentifiers and v = date_convert(v) on VolumeDescriptorDates, and then print. Meaning I need to iterate throughout the data and compare by isintance or by key. Not ideal.

P.S., Notice I had to do a not vdd.year, this is because there's no __bool__ override either, which would help in situations like this.

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

1 participant