Skip to content

Commit

Permalink
chore: fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazyboyQCD committed Jan 24, 2025
1 parent 4497527 commit 5c82d93
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions core/engine/src/builtins/date/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,17 +769,17 @@ pub(super) fn parse_date(date: &JsString, hooks: &dyn HostHooks) -> Option<i64>
};

// Date Time String Format: 'YYYY-MM-DDTHH:mm:ss.sssZ'
if let Some(dt) = DateParser::new(&date, hooks).parse() {
if let Some(dt) = DateParser::new(date, hooks).parse() {
return Some(dt);
}

// `toString` format: `Thu Jan 01 1970 00:00:00 GMT+0000`
if let Ok(t) = OffsetDateTime::parse(&date, &format_description!("[weekday repr:short] [month repr:short] [day] [year] [hour]:[minute]:[second] GMT[offset_hour sign:mandatory][offset_minute][end]")) {
if let Ok(t) = OffsetDateTime::parse(date, &format_description!("[weekday repr:short] [month repr:short] [day] [year] [hour]:[minute]:[second] GMT[offset_hour sign:mandatory][offset_minute][end]")) {
return Some(t.unix_timestamp() * 1000 + i64::from(t.millisecond()));
}

// `toUTCString` format: `Thu, 01 Jan 1970 00:00:00 GMT`
if let Ok(t) = PrimitiveDateTime::parse(&date, &format_description!("[weekday repr:short], [day] [month repr:short] [year] [hour]:[minute]:[second] GMT[end]")) {
if let Ok(t) = PrimitiveDateTime::parse(date, &format_description!("[weekday repr:short], [day] [month repr:short] [year] [hour]:[minute]:[second] GMT[end]")) {
let t = t.assume_utc();
return Some(t.unix_timestamp() * 1000 + i64::from(t.millisecond()));
}
Expand Down Expand Up @@ -836,6 +836,7 @@ impl<'a> DateParser<'a> {
})
}

#[allow(clippy::needless_range_loop)]
fn next_n_digits<const N: usize>(&mut self) -> Option<[u8; N]> {
if self.input.len() < N {
return None;
Expand Down Expand Up @@ -932,15 +933,15 @@ impl<'a> DateParser<'a> {

fn parse_year(&mut self) -> Option<()> {
match self.input.next()? {
&b @ (b'+' | b'-') => {
b @ (b'+' | b'-') => {
let digits = self.next_n_digits::<6>()?.map(i32::from);
let year = digits[0] * 100_000
+ digits[1] * 10000
+ digits[2] * 1000
+ digits[3] * 100
+ digits[4] * 10
+ digits[5];
let neg = b == b'-';
let neg = *b == b'-';
if neg && year == 0 {
return None;
}
Expand Down Expand Up @@ -1009,13 +1010,14 @@ impl<'a> DateParser<'a> {
fn parse_timezone(&mut self) -> Option<()> {
match self.input.next() {
Some(b'Z') => return Some(()),
Some(&b @ (b'+' | b'-')) => {
Some(b @ (b'+' | b'-')) => {
let neg = *b == b'-';
let offset_hour_digits = self.next_n_digits::<2>()?;
let offset_hour = i64::from(offset_hour_digits[0] * 10 + offset_hour_digits[1]);
if offset_hour > 23 {
return None;
}
self.offset = -offset_hour * 60;
self.offset = if neg { offset_hour } else { -offset_hour } * 60;
if self.input.peek().is_none() {
return Some(());
}
Expand All @@ -1026,11 +1028,7 @@ impl<'a> DateParser<'a> {
if offset_minute > 59 {
return None;
}
self.offset += if b == b'-' {
-offset_minute
} else {
offset_minute
};
self.offset += if neg { offset_minute } else { -offset_minute };
}
_ => return None,
}
Expand Down

0 comments on commit 5c82d93

Please sign in to comment.