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

[snapshots] use user locale in timestamp output #3237

Merged
merged 9 commits into from
Nov 16, 2023
Merged

Conversation

sharder996
Copy link
Contributor

@sharder996 sharder996 commented Sep 25, 2023

No description provided.

@sharder996 sharder996 requested a review from ricab September 25, 2023 19:46
std::time_t t = google::protobuf::util::TimeUtil::TimestampToTimeT(timestamp);

// ISO 8601: YYYY-MM-DDThh:mm:ss±hhmm
oss << std::put_time(std::localtime(&t), "%FT%T%z");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently have this set up to print out the UTC offset. Excluding ±hhmm looks a bit more presentable, but then means that the datetime is ambiguous on whether it defines UTC time or localtime. See ISO 8601.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This converts to localtime, which is also necessary (I thought was already the case, so good thing you did that). However, you use a format that is not influenced by the locale (it is standard). To use the locale, I think you would need something like "%c %Z".

The locale needs to be set before this will work, and finding the current locale is platform dependent (e.g. LC_* environment vars on Linux). However, I believe Qt does that for its CoreApplication, so hopefully that would already work. It wouldn't hurt to test on Windows too.

@codecov
Copy link

codecov bot commented Sep 25, 2023

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (7e4dc40) 84.03% compared to head (4a1b2dc) 84.00%.
Report is 12 commits behind head on main.

Files Patch % Lines
src/client/cli/formatter/format_utils.cpp 25.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3237      +/-   ##
==========================================
- Coverage   84.03%   84.00%   -0.04%     
==========================================
  Files         250      250              
  Lines       13464    13482      +18     
==========================================
+ Hits        11315    11326      +11     
- Misses       2149     2156       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ricab
Copy link
Collaborator

ricab commented Sep 28, 2023

Thanks for this @sharder996. I will enqueue this with a little lower priority to focus on PRs that were already on flight. But hopefully we can still get it into the MVP.

@ricab ricab force-pushed the cli-use-local-time branch 2 times, most recently from ce8804a to 9125f5f Compare October 16, 2023 15:59
@ricab ricab force-pushed the snapshots branch 2 times, most recently from ef4a85e to 8b3c7a6 Compare October 25, 2023 18:20
@ricab ricab force-pushed the cli-use-local-time branch from 9125f5f to 09189a0 Compare October 25, 2023 18:20
@bors bors bot changed the base branch from snapshots to main October 31, 2023 07:34
@ricab
Copy link
Collaborator

ricab commented Oct 31, 2023

Hey @sharder, could you please rebase the relevant commits here? Thank you!

Copy link
Collaborator

@ricab ricab left a comment

Choose a reason for hiding this comment

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

Hey @sharder996, thanks for this PR! It looks good overall, both structurally and in detail. However, you are using local time, but not a locale yet. The locale is important in this instance mainly to avoid ambiguity in the date (is 2022-11-02 the same as Nov 2nd or Feb 11th?); to a lesser extent, in the time too (is 1:15 am or pm?).

In any case, this is certainly valuable as is. If it turns out to be difficult to use the locale, we can skip that and accept. But please have a look at my inline comment.

std::time_t t = google::protobuf::util::TimeUtil::TimestampToTimeT(timestamp);

// ISO 8601: YYYY-MM-DDThh:mm:ss±hhmm
oss << std::put_time(std::localtime(&t), "%FT%T%z");
Copy link
Collaborator

Choose a reason for hiding this comment

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

This converts to localtime, which is also necessary (I thought was already the case, so good thing you did that). However, you use a format that is not influenced by the locale (it is standard). To use the locale, I think you would need something like "%c %Z".

The locale needs to be set before this will work, and finding the current locale is platform dependent (e.g. LC_* environment vars on Linux). However, I believe Qt does that for its CoreApplication, so hopefully that would already work. It wouldn't hurt to test on Windows too.

@townsend2010 townsend2010 added this to the 1.13.0 milestone Nov 6, 2023
ricab
ricab previously approved these changes Nov 14, 2023
Copy link
Collaborator

@ricab ricab left a comment

Choose a reason for hiding this comment

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

Thanks @sharder996! This doesn't work within a snap, but I think we can get it in and deal with that separately. I have only a tiny request inline, then we can merge.

#include <multipass/cli/json_formatter.h>
#include <multipass/cli/table_formatter.h>
#include <multipass/cli/yaml_formatter.h>

#include <sstream>

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should include <locale>

Copy link
Collaborator

@ricab ricab left a comment

Choose a reason for hiding this comment

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

Thank you!

bors r+

@ricab
Copy link
Collaborator

ricab commented Nov 15, 2023

bors r+

@ricab
Copy link
Collaborator

ricab commented Nov 15, 2023

Oh oh is bors gone for good?

@townsend2010
Copy link
Contributor

bors ping

@townsend2010
Copy link
Contributor

Ok, CI is all green as are integration tests. Merging...

@townsend2010 townsend2010 merged commit 1d6a056 into main Nov 16, 2023
@townsend2010 townsend2010 deleted the cli-use-local-time branch November 16, 2023 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants