Skip to content

Can I add a custom factory method onto DateTime? #1600

Answered by diesieben07
yeoffrey asked this question in Q&A
Discussion options

You must be logged in to vote

Personally, I would stay far away from mucking around with "other people's prototypes". It has caused nothing but grief in the past (one example: https://developer.chrome.com/blog/smooshgate).
Just write a plain old function:

function dateTimeFromBigQueryTimestamp(bqt: BigQueryTimestamp): DateTime {
   // whatever
}

This also makes it clear that this is your own function and not Luxon's, which has the advantage of making it clearer to understand for other people reading your code. They won't be expecting documentation for this function in Luxon's documentation, but yours.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@yeoffrey
Comment options

Answer selected by yeoffrey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants