8000 date.exe -u argument doesn't work. · Issue #6396 · uutils/coreutils · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

date.exe -u argument doesn't work. #6396

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

Closed
hellishvictor opened this issue May 12, 2024 · 3 comments
Closed

date.exe -u argument doesn't work. #6396

hellishvictor opened this issue May 12, 2024 · 3 comments
Labels

Comments

@hellishvictor
Copy link
hellishvictor commented May 12, 2024

Hi, I think I've found a bug using the -u argument with date.exe. When is used with the GnuWin32 version it shows:
date.exe -u -d "@1715372666" +"%F, %T %Z%z"
2024-05-10, 20:24:26 UTC+0000

And when is not used:
date.exe -d "@1715372666" +"%F, %T %Z%z"
2024-05-10, 21:24:26 Hora de verano GMT+0100

But with coreutils, with or without the -u, it always shows the same time:
coreutils date -d "@1715372666" +"%F, %T %Z%z"
2024-05-10, 20:24:26 +01:00+0100
Here without the -u should be one hour more (21:24:26), and when used it should show +0000.

Cheers.

@DaveKram
Copy link
DaveKram commented Jun 1, 2024

I decided to take a look at this - it seems like the following logic needs to be updated:

let now: DateTime<FixedOffset> = if settings.utc {
let now = Utc::now();
now.with_timezone(& 8000 ;now.offset().fix())
} else {
let now = Local::now();
now.with_timezone(now.offset())
};
// Iterate over all dates - whether it's a single date or a file.
let dates: Box<dyn Iterator<Item = _>> = match settings.date_source {
DateSource::Custom(ref input) => {
let date = parse_date(input.clone());
let iter = std::iter::once(date);
Box::new(iter)
}
DateSource::Human(relative_time) => {
// Get the current DateTime<FixedOffset> for things like "1 year ago"
let current_time = DateTime::<FixedOffset>::from(Local::now());
// double check the result is overflow or not of the current_time + relative_time
// it may cause a panic of chrono::datetime::DateTime add
match current_time.checked_add_signed(relative_time) {
Some(date) => {
let iter = std::iter::once(Ok(date));
Box::new(iter)
}
None => {
return Err(USimpleError::new(
1,
format!("invalid date {}", relative_time),
));
}
}
}

The math up to this point is still using Local::now() (thus current_time still being a Local::now()). I'm thinking that the return value down below should use the now variable's offset() (since that takes into consideration UTC). I.E something like this:

let iter = std::iter::once(Ok(date.with_timezone(now.offset())));

Which changes the string representation of the date to be offset by now, which is based off of whether the -u UTC flag is set or not.

Would like someone to check this (since is my first look at the repo) - can make a PR if is accurate.

Edit: Probably also would need a new test added, since cargo test date passes as is currently.

@mengshengwu
Copy link
Contributor

I think this was fixed in #6503

Test as bellow after that meger:

# GNU date
➜ date -u -d "@1715372666" +"%F, %T %Z%z"
2024-05-10, 20:24:26 UTC+0000
➜ date -d "@1715372666" +"%F, %T %Z%z"
2024-05-11, 04:24:26 CST+0800

# uu_date
➜ cargo r -p uu_date -- -u -d "@1715372666" +"%F, %T %Z%z"
2024-05-10, 20:24:26 +00:00+0000
➜ cargo r -p uu_date -- -d "@1715372666" +"%F, %T %Z%z"
2024-05-11, 04:24:26 +08:00+0800

@hellishvictor
Copy link
Author
6A02 hellishvictor commented Jun 29, 2024

Fixed, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants
0