-
Notifications
You must be signed in to change notification settings - Fork 2
DateRangeToStringConverter #109
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
base: main
Are you sure you want to change the base?
Conversation
marchant
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor needed
| * @param {Object} [options] - An object with formatting options for Intl.DateTimeFormat | ||
| * @returns {string} The formatted date range string | ||
| */ | ||
| convert: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wasn't my guidance: converters only take one argument in the convert method, and since it's a DateRangeToStringConverter, the argument passed to convert has to be a Range instance. locales and options needs to be properties of the converter itself
c22d8b0 to
a4c9bc0
Compare
| * @param {Object} [options] - An object with formatting options for Intl.DateTimeFormat | ||
| */ | ||
| constructor: { | ||
| value: function DateRangeToStringConverter(locales, options) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to avoid having constructors with arguments as much as possible. They can't be used with serialization/deserialization anyway, when subclassing, one has to remember to call it with the expected arguments. Their main benefit is conciseness when used in code / imperatively
| const dateTimeFormat = new Intl.DateTimeFormat(locales, options); | ||
| return dateTimeFormat.formatRange(startDate, endDate); | ||
| value: function (range) { | ||
| const dateTimeFormat = new Intl.DateTimeFormat(this.locales, this.options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no reason to create that object every time convert() is called, is there ?! Please refactor so the converter has only one it reuses.
adds DateRangeToStringConverter which takes (startDate, endDate, locales, options) as parameters to output a stringified date in the specified format