Skip to content
This repository has been archived by the owner on Feb 8, 2022. It is now read-only.

Add strftime cheatsheet for into datetime (#869) #883

Merged
merged 2 commits into from
Jan 31, 2022
Merged

Conversation

voidash
Copy link
Contributor

@voidash voidash commented Jan 29, 2022

Description


 > into datetime --list                                       
╭──────┬─────────────────────────────────────────────────────────────────────────────────────────╮
│ code │ Description                                                                             │
│ %F   │ Year-month-day format. Same to %Y                                                       │
│ %Y   │ The full proleptic Gregorian year, zero-padded to 4 digits(Example: 2001).              │
│ %C   │ The proleptic Gregorian year divided by 100, zero-padded to 2 digits. (Example: 20)     │
│ %y   │ The proleptic Gregorian year modulo 100, zero-padded to 2 digits. (Example: 01)         │
│ %m   │ Month number (01--12), zero-padded to 2 digits.(Example: 07)                            │
│ %b   │ Abbreviated month name. Always 3 letters.(Example: Jul)                                 │
│ %B   │ Full month name. Also accepts corresponding abbreviation in parsing.(Example: July)     │
│ %h   │ Same to %b                                                                              │
│ %d   │ Day number (01--31), zero-padded to 2 digits.(Example: 08)                              │
│ %e   │ Same to %d                                                                              │
│ %a   │ Abbreviated weekday name. Always 3 letters.(Example: Sun)                               │
│ %A   │ Full weekday name. Also accepts corresponding abbreviation in parsing.(Example: Sunday) │
│ %w   │ Sunday = 0, Monday = 1, ..., Saturday = 6.(Example: 0)                                  │
│ %u   │ Monday = 1, Tuesday = 2, ..., Sunday = 7. (ISO 8601)(Example: 7)                        │

Tests

Make sure you've run and fixed any issues with these commands:

  • cargo fmt --all -- --check to check standard code formatting (cargo fmt --all applies these changes)
  • cargo clippy --all --all-features -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect to check that you're using the standard code style
  • cargo build; cargo test --all --all-features to check that all the tests pass

@fdncred
Copy link
Contributor

fdncred commented Jan 29, 2022

nice! i just added #869 to remember this yesterday.

one suggestion, if you want it to be a table (which is just a list of records), you can try and make the return a Value::List of Records instead of adding "code and description" as kind of a header above. so, i think you could do something like:

Value::List {
  vals: vec![Value::Record {
        cols: code,
        vals: description,
        span: head,
    }],
  span: head
}

or perhaps like the bool example

result: Some(Value::List {
vals: vec![
Value::Record {
cols: vec!["value".to_string()],
vals: vec![Value::boolean(false, span)],
span,
},
Value::Record {
cols: vec!["value".to_string()],
vals: vec![Value::boolean(true, span)],
span,
},
Value::Record {
cols: vec!["value".to_string()],
vals: vec![Value::boolean(false, span)],
span,
},
Value::Record {
cols: vec!["value".to_string()],
vals: vec![Value::boolean(true, span)],
span,
},
Value::Record {
cols: vec!["value".to_string()],
vals: vec![Value::boolean(true, span)],
span,
},
],
span,
}),
},

My code may not be precise but you should be able to fish around in the code-base to find a list of records.

@voidash
Copy link
Contributor Author

voidash commented Jan 31, 2022

Thanks for pointing it out; I actually wanted a table. I looked into into/bool.rs and figured it out. Here is the sample output

╭────┬───────────────┬────────────┬─────────────────────────────────────╮
│ #  │ Specification │  Example   │             Description             │
├────┼───────────────┼────────────┼─────────────────────────────────────┤
│  0 │ %Y            │ 2001       │ The full proleptic Gregorian year,  │
│    │               │            │ zero-padded to 4 digits             │

@fdncred
Copy link
Contributor

fdncred commented Jan 31, 2022

That output looks great! It looks so tedious writing all those Value::Record statements. It says to me that we need a helper function because that really looks like a pain to write. haha.

I'll land this as soon as the CI goes green. Thanks for all your hard work!!

@fdncred fdncred merged commit b1aa8f4 into nushell:main Jan 31, 2022
@fdncred
Copy link
Contributor

fdncred commented Jan 31, 2022

i love this so much! ❤️

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants