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

Upgrade to Crystal v0.35.1 #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ ULID.generate
You can also input a seed time which will consistently give you the same string for the time component. This is useful for migrating to ulid.

```crystal
ULID.generate Time.now + 5.second
ULID.generate Time.utc + 5.second
# => "01ARYZ6S41TSV4RRFFQ69G5FAV"
```

Expand Down
2 changes: 1 addition & 1 deletion spec/ulid_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe ULID do
1000.times do
ulid_1 = ULID.generate
sleep 1.millisecond
ulid_2 = ULID.generate(Time.now - 1.second)
ulid_2 = ULID.generate(Time.utc - 1.second)

(ulid_2 < ulid_1).should be_true
end
Expand Down
6 changes: 3 additions & 3 deletions src/ulid.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ module ULID
# ULID.generate
# # => "01B3EAF48P97R8MP9WS6MHDTZ3"
# ```
def generate(seed_time : Time = Time.now) : String
def generate(seed_time : Time = Time.utc) : String
encode_time(seed_time, TIME_LEN) + encode_random(RANDOM_LEN)
end

private def encode_time(now : Time, len : Int32) : String
ms = now.epoch_ms
ms = now.to_unix_ms

String.build do |io|
len.times do |i|
mod = ms % ENCODING_LEN
io << ENCODING[mod]
ms = (ms - mod) / ENCODING_LEN
ms = (ms - mod) // ENCODING_LEN
end
end.reverse
end
Expand Down