Skip to content

xmltemplate contains leap year bugs #213

@mace-space

Description

@mace-space

There appears to be a bug in the implementation of the DATETIME method in xmltemplate.py

For example, for euv2000_364_09_23, it gives the start date and stop date as 2000-12-30 (instead of 2000-12-29) under Time_Coordinates (the year 2000 is a leap year). In the template it uses xmltemplate.py's DATETIME() method to convert the PDS3 UTC times:

       <Time_Coordinates>
                 <start_date_time>$DATETIME(START_TIME)$</start_date_time>
                 <stop_date_time>$DATETIME(STOP_TIME)$</stop_date_time>
          </Time_Coordinates>

I think the bug is here in xmltemplate.py, where it says:

        if len(parts) == 2 and offset == 0:
            # Note that strftime does not support dates before 1900. Some
            # erroneous dates in some labels have erroneous years. This is a
            # workaround.
            day = time.strptime('19' + date[2:], '%Y-%j')
            date = parts[0][:2] + time.strftime('%Y-%m-%d', day)[2:]

            return date + 'T' + hms + ('Z' if not hms.endswith('Z') else '')

If the date is like '2000-364' then these lines parse it as '1900-364', which gives December 30th (because 1900 is not a leap year). This appears to be an unwanted consequence of trying to fix some erroneous years in certain PDS3 labels (but it isn't clear to me which labels contain such anomalies).

Since xmltemplate has been succeeded by pdstemplate, the fix may be simply for users to use pdstemplate (which doesn't appear to have the same bug), but I did want to note there is a bug in xmltemplate.

@markshowalter , @matthewtiscareno what do you think?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions