Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/builtins/azure_policy/template_functions_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,12 @@ fn percent_encode(s: &str) -> String {
// always returns Some for radix 16.
result.push('%');
result.push(
core::char::from_digit(u32::from(b >> 4), 16)
char::from_digit(u32::from(b >> 4), 16)
.unwrap_or('0')
.to_ascii_uppercase(),
);
result.push(
core::char::from_digit(u32::from(b & 0x0F), 16)
char::from_digit(u32::from(b & 0x0F), 16)
.unwrap_or('0')
.to_ascii_uppercase(),
);
Expand Down
8 changes: 7 additions & 1 deletion src/builtins/time/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ const MILLISECOND: u64 = 1000 * MICROSECOND;
const SECOND: u64 = 1000 * MILLISECOND;
const MINUTE: u64 = 60 * SECOND;
const HOUR: u64 = 60 * MINUTE;
const DAY: u64 = 24 * HOUR;
const WEEK: u64 = 7 * DAY;
const YEAR: u64 = 365 * DAY;

#[derive(Debug)]
pub enum ParseDurationError {
Expand Down Expand Up @@ -155,7 +158,10 @@ pub fn parse_duration(mut s: &str) -> Result<Duration, ParseDurationError> {
"s" => SECOND,
"m" => MINUTE,
"h" => HOUR,
unkonwn => return Err(ParseDurationError::UnknownUnit(unkonwn.to_string())),
"d" => DAY,
"w" => WEEK,
"y" => YEAR,
unknown => return Err(ParseDurationError::UnknownUnit(unknown.to_string())),
};

s = &s[idx + 1..];
Expand Down
1 change: 1 addition & 0 deletions src/tests/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ fn yaml_test_impl(file: &str) -> Result<()> {
"globmatch.yaml",
"now_ns.yaml",
"parse_duration_ns.yaml",
"duration_units.yaml",
"parse_ns.yaml",
"parse_rfc3339_ns.yaml",
"weekday.yaml",
Expand Down
26 changes: 26 additions & 0 deletions tests/interpreter/cases/builtins/time/duration_units.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

cases:
- note: days-weeks-years
data: {}
modules:
- |
package test
one_day = time.parse_duration_ns("1d")
one_week = time.parse_duration_ns("1w")
one_year = time.parse_duration_ns("1y")
query: data.test
want_result:
one_day: 86400000000000
one_week: 604800000000000
one_year: 31536000000000000

- note: mixed-units
data: {}
modules:
- |
package test
x = time.parse_duration_ns("1d12h")
query: data.test.x
want_result: 129600000000000
Loading