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

Handling timestamp is incorrect? Or wrong examples just exists in documents? #1

Closed
kachick opened this issue May 2, 2021 · 0 comments · Fixed by #2
Closed

Handling timestamp is incorrect? Or wrong examples just exists in documents? #1

kachick opened this issue May 2, 2021 · 0 comments · Fixed by #2

Comments

@kachick
Copy link
Contributor

kachick commented May 2, 2021

Hi! I have created new ruby library for ULID manipulations as https://github.com/kachick/ruby-ulid 😄
I would like to import test cases from other implementations for robustness, then found this repository.

Some examples looks weird to me, are they actually correct example?

ulid-ruby/lib/ulid.rb

Lines 42 to 47 in 381daa7

# @example Generate a ULID string for a given time
# ULID.at(Time.at(1_000_000)) #=> 0009A0QS00SGEFTGMFFEAS6B9A
#
def self.at(at_time)
Identifier.new(at_time).ulid
end

In my gem

ULID.generate(moment: Time.at(1_000_000))
#=> ULID(1970-01-12 13:46:40.000 UTC: 0000XSNJG0WM2T5DT27HYBT8D4)

The timestamp handling looks correct from following result

Time.at(1_000_000, in: 'UTC')
#=> 1970-01-12 13:46:40 UTC

ulid-ruby/lib/ulid.rb

Lines 54 to 59 in 381daa7

# @example Parse a ULID string and get a time value
# ULID.time '0009A0QS00SGEFTGMFFEAS6B9A' #=> 1970-01-12 13:46:40 UTC
#
def self.time(ulid)
Identifier.new(ulid).time.utc
end

In my gem

ULID.parse('0009A0QS00SGEFTGMFFEAS6B9A').to_time
#=> 1970-04-26 17:46:40 UTC

Ensuring my result is same with https://github.com/oklog/ulid

$ ulid 0009A0QS00SGEFTGMFFEAS6B9A
Sun Apr 26 17:46:40 UTC 1970
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

Successfully merging a pull request may close this issue.

1 participant