dmtrKovalenko / date-io

Abstraction over common javascript date management libraries
MIT License
726 stars 90 forks source link

Refactor arrow-methods from LuxonUtils #619

Closed local-minimum closed 1 year ago

local-minimum commented 2 years ago

Since arrow-methods are not available when sub-classing the LuxonUtils (e.g. to have it always use UTC rather than local-time) through super it would be better if the implementation of IUtils<DateTime> was doing something like:

export default class LuxonUtils implements IUtils<DateTime> {
  public date(value?: any): DateTime | null {
     /* ... */
  };

instead of

export default class LuxonUtils implements IUtils<DateTime> {
  public date = (value?: any) => {
     /* ... */
  };

because then subclassing could be done like so (which is not possible when date is defined with => as it is now:

export class LuxonUTCUtils extends LuxonUtils {
  public override date(value?: any): DateTime | null {
    const dt = super.date(value);
    if (dt === null) return null;
    return dt.toUTC();
  };
}
Semigradsky commented 2 years ago

See https://github.com/dmtrKovalenko/date-io/issues/595 also

dmtrKovalenko commented 1 year ago

That was a mistake done by me by converting all of them from the regular js method to class properties, which causes breaking change, so switching back would be another breaking change.

For now please follow this guide https://github.com/dmtrKovalenko/date-io#2-reexport-the-bindings