Skip to content

feat: custom snowflake epoch, various fixes#3

Open
shayypy wants to merge 6 commits intotheinternetfolks:mainfrom
discohook:main
Open

feat: custom snowflake epoch, various fixes#3
shayypy wants to merge 6 commits intotheinternetfolks:mainfrom
discohook:main

Conversation

@shayypy
Copy link
Copy Markdown

@shayypy shayypy commented Apr 4, 2024

Hello, I'm using this package to generate Snowflakes but I wanted to set a custom epoch that makes more sense for my project (I'll never have an ID from 1970-2023, so why bother keeping those 53 redundant years?).

At first I attempted to override Snowflake.EPOCH but this was not working for me in my environment (i.e. snowflakes with the same epoch were generated), and the readme seemed to imply that this parameter should be passed through generate anyway. I also added an epoch parameter to parse so that timestamps with a custom epoch can be parsed correctly.

Unrelated changes that are also in this pull:

  • build package (there were apparently some standing unbuilt changes)
  • add docs for shard_id option on generate
  • fix isValid only accepting ids with length 19
    • snowflakes are of course generated with timestamps, so they get longer with time. my snowflake generated 4 months after its epoch was only 17 digits long, and new twitter snowflakes are 19, but I went to 22 as a cautionary measure (feel free to change)
  • fix incorrectly named shift (start) parameter in doc

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 this pull request may close these issues.

1 participant