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

switch from chrono to time #1790

Merged
merged 3 commits into from
Mar 20, 2022
Merged

Conversation

mwcz
Copy link
Contributor

@mwcz mwcz commented Mar 7, 2022

This PR replaces the chrono crate with the time crate.

It also makes a subtle internal change in how times are used within Zola. Previously, NaiveDateTime from the chrono crate was used everywhere, which omits timezone offset. If a timezone offset is given to Zola in a post's front matter, it will be flattened into a NaiveDateTime by adding the offset to the datetime. If you tell Zola "this post happened at 4:00+2:00", Zola would convert that to "6:00". Now, the offset is preserved, and UTC is assumed when no offset is provided. The old system was implicitly "convert everything to UTC" and the new system is "assume UTC unless otherwise specified". There's no change in Zola's behavior, though.

Sanity check:

  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

Code changes

(Delete or ignore this section for documentation changes)

  • Are you doing the PR on the next branch?

If the change is a new feature or adding to/changing an existing one:

  • Have you created/updated the relevant documentation page(s)?
    • I don't think any documentation needs to be updated, but there is a random typo fix in the docs in a section about time.

src/cmd/serve.rs Outdated
Comment on lines 534 to 538
let format = format_description!("[year]-[month]-[day] [hour]:[minute]:[second] UTC");
println!(
"Change detected @ {}",
OffsetDateTime::now_utc().format(&format).unwrap().to_string()
);
Copy link
Contributor Author

@mwcz mwcz Mar 7, 2022

Choose a reason for hiding this comment

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

@Keats This timestamp is the only reason the root crate needs a dependency on time. It also includes very very minor regression because with chrono, Zola could print the change detected timestamp in the user's local timezone. time can't do that in multithreaded applications. There's some kind of UB/unsoundness around getting local time in a thread, which is why this is now printing UTC times.

What do you think of just doing println!("Change detected") and dropping the timestamp? Then the root crate wouldn't need a dependency on time.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it only on MacOS? I kind of like having the datetime in there to make sure I'm getting the changes when I expect them (eg I see nothing changing on the site and I check the the terminal to see if it has been picked up).
At the same time, if it's not showing the local timezone it's not worth it.
It's kinda weird it's not possible though, can we get the user offset on startup before starting any threads and re-using it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like that should be possible, I'll look into it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That issue indicates it is only on Mac OS but it was happening to me on Fedora. Calling now_local was Err.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Keats Grabbing the UTC offset before threading starts worked like a charm. patch pushed to this branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did have to add another argument to serve(), but thankfully #[allow(clippy::too_many_arguments)] was already there. 😅

components/libs/Cargo.toml Outdated Show resolved Hide resolved
@@ -5,7 +5,7 @@ edition = "2021"

[dependencies]
serde = {version = "1.0", features = ["derive"] }

time = { version = "0.3", features = ["macros"] }
Copy link
Collaborator

Choose a reason for hiding this comment

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

are the macros only used for tests? If so, we should probably remove that dep entirely from this crate and build them manually

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can't remove the crate, or the macro feature, because they're used in for example, front_matter's parse_datetime:

https://github.com/getzola/zola/pull/1790/files#diff-313e3525c8ae290a23638c1248f2514eada393c295f005ec3c8702c2f7c521a4R73-R79

src/cmd/serve.rs Outdated
Comment on lines 534 to 538
let format = format_description!("[year]-[month]-[day] [hour]:[minute]:[second] UTC");
println!(
"Change detected @ {}",
OffsetDateTime::now_utc().format(&format).unwrap().to_string()
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it only on MacOS? I kind of like having the datetime in there to make sure I'm getting the changes when I expect them (eg I see nothing changing on the site and I check the the terminal to see if it has been picked up).
At the same time, if it's not showing the local timezone it's not worth it.
It's kinda weird it's not possible though, can we get the user offset on startup before starting any threads and re-using it?

@Keats
Copy link
Collaborator

Keats commented Mar 20, 2022

This is a scheduled windows-2016 brownout. The windows-2016 environment is deprecated and will be removed on April 1st, 2022.

Damn looks like we need to fix the Windows CI build soon.

@Keats Keats merged commit 336a271 into getzola:next Mar 20, 2022
@mwcz
Copy link
Contributor Author

mwcz commented Mar 20, 2022

This is a scheduled windows-2016 brownout. The windows-2016 environment is deprecated and will be removed on April 1st, 2022.

Damn looks like we need to fix the Windows CI build soon.

😬

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.

2 participants