Write docs; Improve Time Display

This commit is contained in:
Jeff 2023-08-24 00:26:37 -04:00
parent 19249c0e50
commit 2744ecf387
3 changed files with 17 additions and 14 deletions

View File

@ -242,10 +242,13 @@ impl Tool for Select {
identifier: "select", identifier: "select",
description: "Extract one or more values based on their key.", description: "Extract one or more values based on their key.",
group: "collections", group: "collections",
inputs: vec![ValueType::ListExact(vec![ inputs: vec![
ValueType::ListExact(vec![ValueType::Table, ValueType::String]),
ValueType::ListExact(vec![
ValueType::Table, ValueType::Table,
ValueType::ListOf(Box::new(ValueType::String)), ValueType::ListOf(Box::new(ValueType::String)),
])], ]),
],
} }
} }

View File

@ -1,6 +1,6 @@
use std::{ use std::{
fmt::{self, Display, Formatter}, fmt::{self, Display, Formatter},
time::{Instant, SystemTime, UNIX_EPOCH}, time::{Instant, SystemTime},
}; };
use chrono::{DateTime, FixedOffset, Local as LocalTime, NaiveDateTime}; 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<SystemTime> for Time { impl From<SystemTime> for Time {
fn from(value: SystemTime) -> Self { fn from(value: SystemTime) -> Self {
let timestamp = value.duration_since(UNIX_EPOCH).unwrap().as_micros(); Time::Local(value.into())
let naive = NaiveDateTime::from_timestamp_micros(timestamp as i64).unwrap();
Time::Utc(naive)
} }
} }

View File

@ -6,7 +6,10 @@ use std::{
use crate::{value::Value, Error, Result, Table, TOOL_LIST}; 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)] #[derive(Clone, Debug, PartialEq, PartialOrd, Ord, Eq, Serialize, Deserialize)]
pub struct VariableMap { pub struct VariableMap {
variables: BTreeMap<String, Value>, variables: BTreeMap<String, Value>,
@ -95,8 +98,8 @@ impl VariableMap {
pub fn set_value(&mut self, identifier: &str, value: Value) -> Result<()> { pub fn set_value(&mut self, identifier: &str, value: Value) -> Result<()> {
let split = identifier.split_once('.'); let split = identifier.split_once('.');
if let Some((map_name, next_identifier)) = split { if let Some((identifier, next_identifier)) = split {
let get_value = self.variables.get_mut(map_name); let get_value = self.variables.get_mut(identifier);
if let Some(found_value) = get_value { if let Some(found_value) = get_value {
if let Value::List(list) = found_value { if let Value::List(list) = found_value {
@ -130,7 +133,7 @@ impl VariableMap {
new_map.set_value(next_identifier, value)?; new_map.set_value(next_identifier, value)?;
self.variables self.variables
.insert(map_name.to_string(), Value::Map(new_map)); .insert(identifier.to_string(), Value::Map(new_map));
Ok(()) Ok(())
} }