Skip to content
This repository has been archived by the owner on May 4, 2021. It is now read-only.

Use ISO8601 as the DPN date-time format #128

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open

Conversation

dazza-codes
Copy link
Contributor

@dazza-codes dazza-codes commented Oct 27, 2016

Exploring an alternative solution to #124 (cf. #125); may also fix #131

This solution focuses on using the ISO8601 datetime format. The last commit ensures it, but if the date format must or should be a parameter, the last commit can be dropped.

http://www.iso.org/iso/home/standards/iso8601.htm

@dazza-codes dazza-codes changed the title WIP to remove config/initializers/time_formats.rb Remove config/initializers/time_formats.rb Oct 27, 2016
@dazza-codes dazza-codes mentioned this pull request Oct 27, 2016
@dazza-codes
Copy link
Contributor Author

dazza-codes commented Oct 28, 2016

@Pcolar - does the DPN specification use ISO8601 for date formats? If not, what? Where is it defined? I assume it is defined somewhere, but have not yet found the details, e.g.

This page does not explicitly identify ISO8601 as the DPN date-time standard:

@Pcolar
Copy link
Member

Pcolar commented Oct 28, 2016

Date fields in DPN use ISO 8601. That was decided during the initial design and documented:
https://wiki.duraspace.org/display/DPN/Registry

last_fixity_date: ISO 8601
creation_date: ISO 8601
last_modified_date: ISO 8601

@dazza-codes
Copy link
Contributor Author

@dazza-codes dazza-codes changed the title Remove config/initializers/time_formats.rb Use ISO8601 as the DPN date-time format Oct 28, 2016
@malakai97
Copy link
Contributor

malakai97 commented Oct 28, 2016

I think the confusion is arising because there are many iso8601 date formats.

@dazza-codes
Copy link
Contributor Author

dazza-codes commented Oct 28, 2016

So long as the implementation can parse/return any of the iso8601 formats, it complies with the specification. Is there an additional requirement to use only a subset of the iso8601 formats? If so, should we elaborate on the reasons for that?

With regard to implementation details, it may help to look at the ruby API used, e.g.

@dazza-codes
Copy link
Contributor Author

In this PR, the #iso8601 method is used, which is an alias for #xmlschema, which is defined as:

# File activesupport/lib/active_support/time_with_zone.rb, line 134
    def xmlschema(fraction_digits = 0)
      fraction = if fraction_digits.to_i > 0
        (".%06i" % time.usec)[0, fraction_digits.to_i + 1]
      end

      "#{time.strftime("%Y-%m-%dT%H:%M:%S")}#{fraction}#{formatted_offset(true, 'Z')}"
    end

Copied from http://apidock.com/rails/ActiveSupport/TimeWithZone/xmlschema

@mikejritter
Copy link
Contributor

Is there an additional requirement to use only a subset of the iso8601 formats?

iirc it originally came from wanting compatibility between all implementations, though even that I'm not clear on (or why it would be necessary since a good DateTime library should handle everything). Other than that using utc 0 as the time zone seems to be mostly for convenience reasons - like spot checking dates when testing and the like.

@dazza-codes dazza-codes changed the title Use ISO8601 as the DPN date-time format [WIP] Use ISO8601 as the DPN date-time format Oct 28, 2016
@dazza-codes
Copy link
Contributor Author

This will need to be rebased and revised to adjust to the changes now merged from #125

@dazza-codes
Copy link
Contributor Author

  • rebased and revised.

@dazza-codes dazza-codes changed the title [WIP] Use ISO8601 as the DPN date-time format Use ISO8601 as the DPN date-time format Oct 28, 2016
@Pcolar
Copy link
Member

Pcolar commented Oct 31, 2016

Some parsing of the input data is not part of the active support library.
According to the Specifications, DPN will conform to ISO8601 standard. Go and JAVA libraries also support ISO8601.
One initializer in Develop uses a custom method for DateTime strings which strips milliseconds.
(https://github.com/dpn-admin/dpn-server/blob/develop/config/time_formats.rb#L9)

Unit tests are needed to demonstrate this use case.
Can we replicate issues with timestamp granularity?

map_from_public public_field do |value|
{model_field => time_from_public(value)}
end
map_to_public model_field do |value|
{public_field => value.strftime(date_format)}
{public_field => value.iso8601}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although there were no problems in the specs, possibly because they are using the same method, this may not be correct. It might need to be modified to first ensure it is a UTC time, e.g.

[21] pry(BagAdapter)> Time.now.iso8601
=> "2016-10-31T13:46:26-07:00"
[22] pry(BagAdapter)> Time.now.utc.iso8601
=> "2016-10-31T20:46:34Z"

@dazza-codes dazza-codes changed the title Use ISO8601 as the DPN date-time format [WIP] Use ISO8601 as the DPN date-time format Oct 31, 2016
@dazza-codes dazza-codes changed the title [WIP] Use ISO8601 as the DPN date-time format Use ISO8601 as the DPN date-time format Oct 31, 2016
@dazza-codes
Copy link
Contributor Author

If this PR were adopted, some commit squashing can be done to tidy it up. Leaving them as separate commits while this PR is open for review, in case there is discussion about using one or another alternative implementation.

@dazza-codes dazza-codes changed the title Use ISO8601 as the DPN date-time format [WIP] Use ISO8601 as the DPN date-time format Oct 31, 2016
@dazza-codes dazza-codes changed the title [WIP] Use ISO8601 as the DPN date-time format Use ISO8601 as the DPN date-time format Nov 1, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants