From 2744ecf3874723e3dc76598b1e99d63f9156f7cd Mon Sep 17 00:00:00 2001 From: Jeff Date: Thu, 24 Aug 2023 00:26:37 -0400 Subject: [PATCH] Write docs; Improve Time Display --- src/tools/collections.rs | 11 +++++++---- src/value/time.rs | 9 +++------ src/value/variable_map.rs | 11 +++++++---- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/tools/collections.rs b/src/tools/collections.rs index 91f30af..da4cfc6 100644 --- a/src/tools/collections.rs +++ b/src/tools/collections.rs @@ -242,10 +242,13 @@ impl Tool for Select { identifier: "select", description: "Extract one or more values based on their key.", group: "collections", - inputs: vec![ValueType::ListExact(vec![ - ValueType::Table, - ValueType::ListOf(Box::new(ValueType::String)), - ])], + inputs: vec![ + ValueType::ListExact(vec![ValueType::Table, ValueType::String]), + ValueType::ListExact(vec![ + ValueType::Table, + ValueType::ListOf(Box::new(ValueType::String)), + ]), + ], } } diff --git a/src/value/time.rs b/src/value/time.rs index b6ff386..f70d9b3 100644 --- a/src/value/time.rs +++ b/src/value/time.rs @@ -1,6 +1,6 @@ use std::{ fmt::{self, Display, Formatter}, - time::{Instant, SystemTime, UNIX_EPOCH}, + time::{Instant, SystemTime}, }; use chrono::{DateTime, FixedOffset, Local as LocalTime, NaiveDateTime}; @@ -50,7 +50,7 @@ impl Time { ), }; - date_time.to_string() + date_time.to_rfc2822() } } @@ -80,9 +80,6 @@ impl<'de> Deserialize<'de> for Time { impl From for Time { fn from(value: SystemTime) -> Self { - let timestamp = value.duration_since(UNIX_EPOCH).unwrap().as_micros(); - let naive = NaiveDateTime::from_timestamp_micros(timestamp as i64).unwrap(); - - Time::Utc(naive) + Time::Local(value.into()) } } diff --git a/src/value/variable_map.rs b/src/value/variable_map.rs index 0ac521a..f9fb01d 100644 --- a/src/value/variable_map.rs +++ b/src/value/variable_map.rs @@ -6,7 +6,10 @@ use std::{ use crate::{value::Value, Error, Result, Table, TOOL_LIST}; -/// A context that stores its mappings in hash maps. +/// A collection dust variables comprised of key-value pairs. +/// +/// The inner value is a BTreeMap in order to allow VariableMap instances to be sorted and compared +/// to one another. #[derive(Clone, Debug, PartialEq, PartialOrd, Ord, Eq, Serialize, Deserialize)] pub struct VariableMap { variables: BTreeMap, @@ -95,8 +98,8 @@ impl VariableMap { pub fn set_value(&mut self, identifier: &str, value: Value) -> Result<()> { let split = identifier.split_once('.'); - if let Some((map_name, next_identifier)) = split { - let get_value = self.variables.get_mut(map_name); + if let Some((identifier, next_identifier)) = split { + let get_value = self.variables.get_mut(identifier); if let Some(found_value) = get_value { if let Value::List(list) = found_value { @@ -130,7 +133,7 @@ impl VariableMap { new_map.set_value(next_identifier, value)?; self.variables - .insert(map_name.to_string(), Value::Map(new_map)); + .insert(identifier.to_string(), Value::Map(new_map)); Ok(()) }