Add constructors to DateTime and other classes
See original GitHub issueIs your feature request related to a problem? Please describe. I find it confusing that the constructors of DateTime and other classes (e.g. Interval, etc.) are default constructors (i.e. do nothing) and all fields do not have defaults, thereby meaning that the constructors construct essentially invalid objects, specifically:
const dateTime = new DateTime()
fails with TypeError: Cannot read property 'zone' of undefined
Describe the solution you’d like
Since the constructor fails, it would be sensible to implement it to do the same as DateTime.now()
. This would give the same functionality as https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date#syntax which would simplify migration to Luxon
Describe alternatives you’ve considered
If returning the current datetime is not preferred, an alternative implementation could be to return DateTime.fromMillis(0)
to return the epoch
An easier alternative to implementing the constructor would be to make them protected, such that the only way to construct it would be via the static methods or in a derived class.
Additional context
The failing constructor was observed with "@types/luxon" "1.25.0"
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:8 (3 by maintainers)
@thw0rted some context here is that we changed doc processors, and probably just haven’t tracked down all the stuff that works differently. This may be one of those
@thw0rted yeah, our new doc processor doesn’t seem to respect the private flag at least as I have written now. I’d prefer to just fix that so that the constructor disappears from the docs.