Closed MarcelFinkbeiner closed 9 months ago
generated by chatgpt checked by human
I am sorry, but I am not sure what purpose this issue is supposed to have. The argument given hardly makes sense, which makes sense considering it was generated by an LLM. If you have a legitimate use-case, please elaborate what you want to achieve and why.
@diesieben07 what my problem is I want to pass the toLocaleString Presets as string not as an object?
Lets say I write an method getTime and I want to pass the format (Presets: https://moment.github.io/luxon/#/formatting?id=presets) as string, like 'DATE_SHORT' instead of import DateTime everytime.
And instead of using this string with an if else chain or an switch I'd like to pass it directly to the toLocaleString method of luxon/DateTime
You can simply use a normal JavaScript property lookup:
import {DateTime} from 'luxon';
const formatPreset = 'DATE_SHORT'; // get from wherever instead of hardcoding
const date = DateTime.now();
console.log(date.toLocaleString(DateTime[formatPreset]));
You can simply use a normal JavaScript property lookup:
import {DateTime} from 'luxon'; const formatPreset = 'DATE_SHORT'; // get from wherever instead of hardcoding const date = DateTime.now(); console.log(date.toLocaleString(DateTime[formatPreset]));
But this is the point I don't want to import luxon everytime. I have a util file which handles everything regarding luxon which I had to import. It would be a QOL feature ;)
I don't think we should be adding features to reduce the amount of characters people need to type.
Personally I can just recommend to get a modern IDE, like Visual Studio Code (or WebStorm if you want to spend money), which will handle imports for you and can improve your productivity in many other ways as well. In my opinion this is a much more productive endeavor over trying to find ways to reduce how many imports you have to do manually.
Hello
Is your feature request related to a problem? Please describe. Currently,
toLocaleString
can only take aDateTime
object as an argument. This can be limiting in cases where the date/time information is already available in string format and needs to be formatted according to a specific locale.Describe the solution you'd like It would be helpful if
toLocaleString
could also accept a string as an argument, in addition to aDateTime
object. This would allow users to format date/time information from a string using the same locale formatting options available withtoLocaleString
.For example, instead of only being able to use
dt.toLocaleString(DateTime.TIME_SIMPLE)
, I could usedt.toLocaleString('TIME_SIMPLE')
to format a string containing date/time information.Describe alternatives you've considered One alternative solution would be to create a new
DateTime
object from the string and then pass it totoLocaleString
. However, this adds unnecessary complexity and could result in errors if the string is not formatted correctly.Additional context N/A
Regards Marcel