-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to specify format and parsing format in dateHelper functions #13500
Allow to specify format and parsing format in dateHelper functions #13500
Conversation
Okay in a working project I had to use this to switch parsing format based on user locale:
I am not sure if there is a specific way label property editor format the date value based on user locale, so we know how to parse the format a bit more dynamically? |
Hi @bjarnef, Thanks for your detailed description, dashboard and replication steps! Before I start looking at getting this one running, as the history of this is quite long, please could you give me a summary of:
Once I have that, I will know how to test the current behaviour, and then observe the change that the PR makes, and we can progress from there. Best, Emma 😃 |
Hi @emmagarland The use-case it that we are storing some datetime properties in "Label (datetime)" on some course (content) nodes. Some of the node properties are shown in table rows (custom directive) and furthermore we have for each row an inline button to show more details. The details view/overlay get the course nodes data using So the parsing would fails if date time (from
So we have a workaround using moment directly. The changes in this PR still using Furthermore it also allow how to format at server time format, e.g. in a dashboard. It could of course format that date once again, but seems to be redundant, if it can just be formatted correctly in first place (e.g. a server time format presented in a dashboard formatted the current backoffice user). Currently I think these methods are only used sparingly in Settings or Users section of backoffice. and yes the PR is ready for review :) |
Thanks @bjarnef for your reply. I have started to try and replicate the behaviour using your provided package and instructions. So far, I have got "Invalid date" when switching back to a label from a DateTime, but I will restart this with fresh data to double check. Many thanks again, I'll be in touch soon! Emma |
Hi @bjarnef! I've been testing the existing behaviour using the following steps:
Switching to your PR branch and following the same steps, step 16 still shows "Invalid Date": When you get chance, please could you verify my steps above and that the same thing happens to you? Or is there a step missing in my replication steps? Just so you know, the code in the
Or is this a different and unrelated issue? Best regards Emma |
Hi @bjarnef Sorry, bear with me a moment, I think I was running the wrong thing when testing this. I will let you know shortly... Emma |
OK, using this as the correct branch (sorry!) I can confirm that now on step 16 above, using 25/05/2023, I view the following instead of "Invalid Date" on the DateTime field: However, when I change to a label DateTime type, I still observe the invalid date: Are you able to confirm the same, and is this something you expected would be fixed in this PR or is it something else? Thanks 🙂 |
Hi @bjarnef Sorry, forgot to tag you in the last comment! I was just wondering if you were experiencing the same behaviour or if this isn't related to this PR? Thanks Emma |
Hi @emmagarland E.g. if a web service/ api deliver dates in Danish format and one wanted to present the data in a dashboard. |
Thanks @bjarnef Before merging this, I just want to check if this PR relates to #14400 I was looking at, where the Danish scheduled publish fails due to the date having full stops instead of colons. Do you think that if PR #14400 fixes it, this would still be necessary, or could this be resolved by that PR instead? Thanks Emma |
@bjarnef FYI that date PR is now in 😃 Emma |
As for #14400 - this will be a server issue and this PR will not solve it. |
Hi @bjarnef Update on this PR. I've managed to replicate passing a format into the Setup: As an en-GB locale user on this PR branch, I installed your dashboard package and added the properties described on your instructions, The dashboard view: The dashboard is using the code:
And the dashboard: The console view: This is as expected, and not passing in a format handles it as before, so it isn't breaking ("YYYY-MM-DD HH:mm:ss"). However, I am still getting the "invalid date" issue when I convert the datetime label back to a datetime picker. Are you able to replicate that it happens to you, too? Thanks Emma |
Hi @emmagarland Regarding the original use-case I had, I actually used this to convert the display label datetime (depending on backoffice user locale to correct parsing format) as it currently expect the format to be Regarding change "label (datetime)" property back to datetime, I think it may be error at server side. For the label property editor, did you use "Label (DateTime)" and not "Label (String)". Umbraco has some issues, when converting changing datatype to a different property editor using a different value type. |
@bjarnef yes I did use I think it happens on certain dates, such as 25/05/2023, although I don't think it is related to this PR I just wanted to verify behaviour above. Thanks, Emma |
… v11/feature/datehelper-parsing-format
Hi @emmagarland When I have a backoffice user (en-US) and select 25/05/2023 (May 25, 2023) and switch the property to "Label (datetime)" this is shown on document: And in the details dialog using parsing format
The variable E.g.
When I change the backoffice user locale to "en-GB" the display label is different though: 25/05/2023 00:00:00 Now the variable
However with It is because the raw value "25/05/2023 00:00:00" returned by the property and using "en-GB", the parsing format should not be So that's is basically why I needed to specify in the parsing format in the use-case, because I in a custom table view at each row had a button to show details, which fetched data from the existing document and its properties (or some of them), but manipulating the views to the values as labels. |
Hi @bjarnef, Thanks so much for your explanations and patience with me on this pull request to allow people to specify the format and parsing format in It has now been successfully merged! 🙌 I don't think Bellissima is going to be implementing datetimes in the same way, so I haven't tagged this for v14, but I'm sure you will spot if this isn't the case! Much appreciate your ongoing efforts, Best regards Emma |
Prerequisites
If there's an existing issue for this PR then this fixes #13477
Description
Currently when using
dateHelper.getLocalDate()
this expect to parse date in formatYYYY-MM-DD HH:mm:ss
, but sometimes the date may be different, e.g. returned from "Label (datetime)" when fetchingcontentResource.getById(nodeId)
and looping its properties. Depending on the backoffice user thevalue
property may be different, see #13477 (comment)Furthermore moment.js also allow to use
moment.ISO_8601
here when parsing from a known date format: https://momentjs.com/guides/#/parsing/known-formats/Start Date property is using Date Picker and End Date was using Date Picker, but switched property editor to Label (datetime) after selecting a date. In both cases date is December 1st 2022.
In the following example from a dashboard
formatDatesToLocal()
functiond3
is returning an incorrect date, where currentUser.locale isen-US
. On the other handd1
andd2
returns the same correct parsed date.I have attached the dashboard here - just unzip it to
App_Plugins
folder 🤗MyDashboard.zip
Furthermore with default starterkit add a "Details" group to Home Page document type with two properties "Start Date (startDate)" and "End Date (endDate)" using standard "Date Picker" datatype instance with default configuration. Next go to Home Page node and select December 1st 2022 in both date pickers and click Save & Publish. Go back to Home Page document type and change End Date property to use standard "Label (datetime)" datatype instead.
You probably also need to change value of
id
property inshowDetails
function in dashboard.controller.js to match the node id of Home Page.Now inspect the data in console when clicking "Show details" button in dashboard.
It is possible to handle this using moment.js directly or add your own service, but it would be great to use core
dateHelper
for this, which may also solve issues if developers change default from in date pickers.chrome_JJQxS2aJ9b.mp4
switching language of backoffice user to Danish still seems to work although the date format is not
MM/DD/YYYY HH:mm:ss
but insteadDD.MM.YYYY HH:mm:ss