mirror of
https://github.com/nushell/nushell.git
synced 2025-04-16 01:08:21 +02:00
Merge f33ab30d13
into 885b87a842
This commit is contained in:
commit
ed6a0ff1f6
@ -1,13 +1,23 @@
|
|||||||
use chrono::{DateTime, FixedOffset, Local, LocalResult, TimeZone};
|
use chrono::{DateTime, FixedOffset, Local, LocalResult, TimeZone};
|
||||||
use nu_protocol::{record, ShellError, Span, Value};
|
use nu_protocol::{record, ShellError, Span, Value};
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
pub(crate) fn parse_date_from_string(
|
pub(crate) fn parse_date_from_string(
|
||||||
input: &str,
|
input: &str,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> Result<DateTime<FixedOffset>, Value> {
|
) -> Result<DateTime<FixedOffset>, Value> {
|
||||||
match dtparse::parse(input) {
|
match dtparse::Parser::default().parse(
|
||||||
Ok((native_dt, fixed_offset)) => {
|
input,
|
||||||
let offset = match fixed_offset {
|
Some(true),
|
||||||
|
Some(true),
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
None,
|
||||||
|
false,
|
||||||
|
&HashMap::new(),
|
||||||
|
) {
|
||||||
|
Ok(result) => {
|
||||||
|
let offset = match result.1 {
|
||||||
Some(offset) => offset,
|
Some(offset) => offset,
|
||||||
None => *Local
|
None => *Local
|
||||||
.from_local_datetime(&native_dt)
|
.from_local_datetime(&native_dt)
|
||||||
@ -15,7 +25,7 @@ pub(crate) fn parse_date_from_string(
|
|||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.offset(),
|
.offset(),
|
||||||
};
|
};
|
||||||
match offset.from_local_datetime(&native_dt) {
|
match offset.from_local_datetime(&result.0) {
|
||||||
LocalResult::Single(d) => Ok(d),
|
LocalResult::Single(d) => Ok(d),
|
||||||
LocalResult::Ambiguous(d, _) => Ok(d),
|
LocalResult::Ambiguous(d, _) => Ok(d),
|
||||||
LocalResult::None => Err(Value::error(
|
LocalResult::None => Err(Value::error(
|
||||||
|
Loading…
Reference in New Issue
Block a user