Skip to content

Commit

Permalink
Check every minute for timezone update.
Browse files Browse the repository at this point in the history
  • Loading branch information
C0D3-M4513R committed Apr 4, 2022
1 parent 0b04ff2 commit ed149f7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "time"
version = "0.1.2"
version = "0.1.3"
edition = "2021"
publish = false

Expand Down
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The produced executable will expect a path to a file.
In that file specified the current time will be written.

## Known potential problems
- On Windows the program will not apply any changes to Daylight Savings Time, when running. You need to restart the application.
- On Windows the program will check for changes to the timezone every minute.
- On Platforms other than Windows the program will always write UTC to the file.

Example commandline: `time.exe "C:\Users\some-user\Documents\time.txt"`
7 changes: 5 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ It will be used for this program, to write the current system time to.
#[cfg(debug_assertions)]
let mut times = 0;

let mut hour = 0;
let mut min = 0;
loop {
let time = std::time::SystemTime::now();
let s = Instant::now();
Expand All @@ -50,7 +50,8 @@ It will be used for this program, to write the current system time to.
let seconds = local.as_secs() % 60;
let minutes = local.as_secs() / 60 % 60;
let hours = local.as_secs() / 60 / 60 % 24;
if hour != hours {
if min != minutes {
min = minutes;
timezone = get_convert_utc_to_local();
}
let time = format!("{:02}:{:02}:{:02}", hours, minutes, seconds);
Expand Down Expand Up @@ -107,6 +108,8 @@ fn pause() {
println!("Resuming.");
}
fn get_convert_utc_to_local() -> impl Fn(Duration) -> Duration {
#[cfg(debug_assertions)]
println!("Checking Timezone");
#[cfg(target_family = "windows")]
{
windows::get_convert_utc_to_local()
Expand Down

0 comments on commit ed149f7

Please sign in to comment.