Edit docs; Fix subtraction bug
This commit is contained in:
parent
18e4fef62f
commit
88c4207aeb
11
README.md
11
README.md
@ -125,12 +125,17 @@ replace(message, "hate", "love")
|
|||||||
|
|
||||||
### Lists
|
### 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
|
```dust
|
||||||
list = (true, 42, "Ok");
|
list = (true, 41, "Ok");
|
||||||
|
|
||||||
assert_equal(list.0, true);
|
assert_equal(list.0, true);
|
||||||
|
|
||||||
|
list.1 = list.1 + 1;
|
||||||
|
|
||||||
|
assert_equal(list.1, 42);
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Maps
|
### Maps
|
||||||
@ -165,7 +170,7 @@ Querying a table is similar to SQL.
|
|||||||
```dust
|
```dust
|
||||||
names = select(animals, "name");
|
names = select(animals, "name");
|
||||||
youngins = where(animals, 'age < 5');
|
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.
|
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.
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
//! Representation of a moment in time.
|
//! Representation of a moment in time.
|
||||||
//!
|
//!
|
||||||
//! Whale represent time values correctly. To do this, there must be a clear separation between
|
//! Dust tries to represent time values correctly. To do this, there must be a clear separation
|
||||||
//! monotonic timestamps, naive times that do not know their locale and those that have a timezone.
|
//! 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
|
//! 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.
|
//! included, which will use no timezone offset if one is not available.
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
fmt::{self, Display, Formatter},
|
fmt::{self, Display, Formatter},
|
||||||
time::{Instant, SystemTime},
|
time::{Duration, Instant, SystemTime, UNIX_EPOCH},
|
||||||
};
|
};
|
||||||
|
|
||||||
use chrono::{DateTime, FixedOffset, Local as LocalTime, NaiveDateTime};
|
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::Utc(utc) => DateTime::from_utc(utc, FixedOffset::west_opt(0).unwrap()),
|
||||||
Time::Local(local) => local,
|
Time::Local(local) => local,
|
||||||
Time::Monotonic(instant) => DateTime::from_utc(
|
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(),
|
FixedOffset::west_opt(0).unwrap(),
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
@ -65,7 +66,11 @@ impl Time {
|
|||||||
|
|
||||||
impl Display for Time {
|
impl Display for Time {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
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),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 {
|
while missing_elements > 0 {
|
||||||
list.push(value.clone());
|
list.push(value.clone());
|
||||||
|
Loading…
Reference in New Issue
Block a user