diff --git a/README.md b/README.md index 0a701d9..f5cdde6 100644 --- a/README.md +++ b/README.md @@ -125,12 +125,17 @@ replace(message, "hate", "love") ### Lists -Lists are sequential collections. They can be built by grouping values with parentheses and separating them with commas. Values can be indexed by their position to access their contents. Lists are used to represent rows in tables and most commands take a list as an argument. +Lists are sequential collections. They can be built by grouping values with parentheses and separating them with commas. Values can be indexed by their position to access their contents. Lists are used to represent rows in tables and most commands take a list as an argument. Their contents can be indexed using dot notation with an integer. ```dust -list = (true, 42, "Ok"); +list = (true, 41, "Ok"); assert_equal(list.0, true); + +list.1 = list.1 + 1; + +assert_equal(list.1, 42); + ``` ### Maps @@ -165,7 +170,7 @@ Querying a table is similar to SQL. ```dust names = select(animals, "name"); youngins = where(animals, 'age < 5'); -old_species = select_where(animals, "species", 'age > 5') +old_species = select_where(animals, "species", 'age > 5'); ``` The commands `create_table` and `insert` make sure that all of the memory used to hold the rows is allocated at once, so it is good practice to group your rows together instead of using a call for each row. diff --git a/src/value/time.rs b/src/value/time.rs index 757a5d9..634228c 100644 --- a/src/value/time.rs +++ b/src/value/time.rs @@ -1,15 +1,16 @@ //! Representation of a moment in time. //! -//! Whale represent time values correctly. To do this, there must be a clear separation between -//! monotonic timestamps, naive times that do not know their locale and those that have a timezone. +//! Dust tries to represent time values correctly. To do this, there must be a clear separation +//! between monotonic timestamps, naive times that do not know their locale and those that have a .. +//! timezone. //! -//! Only monotonic time instances are guaranteed not to repeat, although and Instance can be used to +//! Only monotonic time instances are guaranteed not to repeat, although an Instant can be used to //! create and of these variants. Users generally want the timezone included, so the `as_local` is //! included, which will use no timezone offset if one is not available. use std::{ fmt::{self, Display, Formatter}, - time::{Instant, SystemTime}, + time::{Duration, Instant, SystemTime, UNIX_EPOCH}, }; use chrono::{DateTime, FixedOffset, Local as LocalTime, NaiveDateTime}; @@ -54,7 +55,7 @@ impl Time { Time::Utc(utc) => DateTime::from_utc(utc, FixedOffset::west_opt(0).unwrap()), Time::Local(local) => local, Time::Monotonic(instant) => DateTime::from_utc( - NaiveDateTime::from_timestamp_micros(instant.elapsed().as_micros() as i64).unwrap(), + NaiveDateTime::from_timestamp_millis(instant.elapsed().as_millis() as i64).unwrap(), FixedOffset::west_opt(0).unwrap(), ), }; @@ -65,7 +66,11 @@ impl Time { impl Display for Time { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - write!(f, "{}", self.as_local()) + match self { + Time::Utc(inner) => write!(f, "{}", inner), + Time::Local(inner) => write!(f, "{}", inner), + Time::Monotonic(inner) => write!(f, "{:?}", inner), + } } } diff --git a/src/value/variable_map.rs b/src/value/variable_map.rs index f9fb01d..e92fd73 100644 --- a/src/value/variable_map.rs +++ b/src/value/variable_map.rs @@ -111,7 +111,7 @@ impl VariableMap { ))); }; - let mut missing_elements = index - list.len() + 1; + let mut missing_elements = index.saturating_sub(list.len()) + 1; while missing_elements > 0 { list.push(value.clone());