Sort history list, put first expiring last

This commit is contained in:
timvisee 2018-05-08 14:13:32 +02:00
parent 77fb9c436d
commit 85e6e3da40
No known key found for this signature in database
GPG key ID: 109CBA0BF74036C2
3 changed files with 15 additions and 5 deletions

View file

@ -1,5 +1,4 @@
# Release 0.1
- Sort history entries
- Panic when secret is missing from URL with info action
- History compiler flag
- Lowercase error messages

View file

@ -167,9 +167,16 @@ impl RemoteFile {
&self.id
}
/// Get the duration the file will expire after,
/// if an expiry time is known.
/// Otherwise `None` is returned.
/// Get the time the file will expire after.
/// Note that this time may not be correct as it may have been guessed,
/// see `expire_uncertain()`.
pub fn expire_at(&self) -> DateTime<Utc> {
self.expire_at
}
/// Get the duration the file will expire after.
/// Note that this time may not be correct as it may have been guessed,
/// see `expire_uncertain()`.
pub fn expire_duration(&self) -> Duration {
// Get the current time
let now = Utc::now();

View file

@ -66,8 +66,12 @@ impl<'a> History<'a> {
Cell::new("OWNER TOKEN"),
]));
// Get the list of files, and sort the first expiring files to be last
let mut files = history.files().clone();
files.sort_by(|a, b| b.expire_at().cmp(&a.expire_at()));
// Add an entry for each file
for (i, file) in history.files().iter().enumerate() {
for (i, file) in files.iter().enumerate() {
// Build the expiry time string
let mut expiry = format_duration(&file.expire_duration());
if file.expire_uncertain() {