Skip to content
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

Desktop: Fixes #10182: Detailed note list doesn't follow preferred date and time formats #10204

Merged
merged 4 commits into from Apr 4, 2024

Conversation

cagnusmarlsen
Copy link
Contributor

Summary

Made changes so that the format of date and time shown in the detailed note list matches the format selected under General > Date format and Time format.

Added a test to check this behavior.

Fixes #10182

Testing

  1. Enable detailed list view via View > Note list style > Detailed
  2. In the note list, show any date field, like Updated and Created
  3. Now, all dates and times are in the format selected by the user.

This has been tested successfully on Windows 11 and Linux.

@@ -89,8 +89,8 @@ class Time {
);
}

public unixMsToLocalDateTime(ms: number): string {
return moment.unix(ms / 1000).format('DD/MM/YYYY HH:mm');
public unixMsToLocalDateTime(ms: number, format?: string): string {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So as you can see in this file, there's already a formatMsToLocal() method that does the same thing and that is already setup to use the preferred date/time format. Can this be used instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that was an oversight on my part. I basically modified unixMsToLocalDateTime to do what formatMsToLocal already does. I have made the changes to use formatMsToLocal instead.

Comment on lines 18 to 22
'note.user_updated_time': () => time.formatMsToLocal(value, options.dateTimeFormat),
'note.user_created_time': () => time.formatMsToLocal(value, options.dateTimeFormat),
'note.updated_time': () => time.formatMsToLocal(value, options.dateTimeFormat),
'note.created_time': () => time.formatMsToLocal(value, options.dateTimeFormat),
'note.todo_completed': () => value ? time.formatMsToLocal(value, options.dateTimeFormat) : '',
Copy link
Owner

@laurent22 laurent22 Mar 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look at formatMsToLocal you see that it's taking a default argument, right? And what is the value of the default argument. Isn't it already the user's preferred date/time format?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that makes sense. I have made the change and also made some changes to the test.

Comment on lines 81 to 88
expect(view).toEqual({
note: {
user_updated_time: time.formatMsToLocal(timeValue),
user_created_time: time.formatMsToLocal(timeValue),
tags: 123,
},
});
});
Copy link
Owner

@laurent22 laurent22 Mar 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel this is not testing much because timeValue is used to generate both the input and expected value, which is generally not a good idea in tests. For example here if formatMsToLocal is broken and returns "undefined", your test will pass even though it's obviously wrong.

The way around this is to use static values in tests. Set timeValue to a known hard-coded timestamp in milliseconds. From that check that you got the expected (hard-coded) formatted date as output.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way around this is to use static values in tests. Set timeValue to a known hard-coded timestamp in milliseconds. From that check that you got the expected (hard-coded) formatted date as output.

That makes sense, but I think the problem here is that because formatMsToLocal converts the timestamp to the user's local time, even if I hard code the expected value, the test would fail in a different timezone. I wonder if there could be another approach to test formatMsToLocal here, perhaps mocking moment?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok so please remove the test then since it does nothing

@laurent22 laurent22 merged commit 6f76fe7 into laurent22:dev Apr 4, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Detailed note list doesn't follow preferred date and time formats
2 participants