question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add constructors to DateTime and other classes

See original GitHub issue

Is 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:open
  • Created 3 years ago
  • Reactions:2
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
icambroncommented, Apr 22, 2022

@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

1reaction
icambroncommented, Apr 21, 2022

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can i set a DateTime value in a new constructor? [duplicate]
I am creating a new customer from my constructor in my customer class and i cannot get the new customer to accept a...
Read more >
DateTime Constructor (System) - Microsoft Learn
This constructor interprets year , month , and day as a year, month, and day in the Gregorian calendar. To instantiate a DateTime...
Read more >
Providing Multiple Constructors in Your Python Classes
In this step-by-step tutorial, you'll learn how to provide multiple constructors in your Python classes. To this end, you'll learn different ...
Read more >
Working with Date and Time in C# - TutorialsTeacher
Use different constructors of the DateTime struct to assign an initial value to a DateTime object. Example: Set Date & Time.
Read more >
datetime — Basic date and time types — Python 3.11.1 ...
If an argument outside those ranges is given, ValueError is raised. Other constructors, all class methods: classmethod date.today() ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found