Skip to content

Commit

Permalink
Add support for single digit dates in parse any functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jrstrunk committed Oct 21, 2024
1 parent 3ec797d commit 60db52d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gleam.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "gtempo"
version = "5.0.0"
version = "5.0.1"

# Fill out these fields if you intend to generate HTML documentation or publish
# your project to the Hex package manager.
Expand Down
4 changes: 2 additions & 2 deletions src/tempo.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -1566,14 +1566,14 @@ pub fn parse_any(

use date_re <- result_guard(
when_error: regex.from_string(
"(\\d{4})[-_/\\.\\s,]{0,2}(\\d{2})[-_/\\.\\s,]{0,2}(\\d{2})",
"(\\d{4})[-_/\\.\\s,]{0,2}(\\d{1,2})[-_/\\.\\s,]{0,2}(\\d{1,2})",
),
return: empty_result,
)

use date_human_re <- result_guard(
when_error: regex.from_string(
"(\\d{2}|January|Jan|january|jan|February|Feb|february|feb|March|Mar|march|mar|April|Apr|april|apr|May|may|June|Jun|june|jun|July|Jul|july|jul|August|Aug|august|aug|September|Sep|september|sep|October|Oct|october|oct|November|Nov|november|nov|December|Dec|december|dec)[-_/\\.\\s,]{0,2}(\\d{2})[-_/\\.\\s,]{0,2}(\\d{4})",
"(\\d{1,2}|January|Jan|january|jan|February|Feb|february|feb|March|Mar|march|mar|April|Apr|april|apr|May|may|June|Jun|june|jun|July|Jul|july|jul|August|Aug|august|aug|September|Sep|september|sep|October|Oct|october|oct|November|Nov|november|nov|December|Dec|december|dec)[-_/\\.\\s,]{0,2}(\\d{1,2})[-_/\\.\\s,]{0,2}(\\d{4})",
),
return: empty_result,
)
Expand Down
10 changes: 10 additions & 0 deletions test/tempo_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ pub fn parse_any_date_test() {
|> should.equal(#(Some(date.literal("2024-06-22")), None, None))
}

pub fn parse_any_date_single_digit_test() {
tempo.parse_any("2024/6/2")
|> should.equal(#(Some(date.literal("2024-06-02")), None, None))
}

pub fn parse_any_date_single_digit_human_test() {
tempo.parse_any("7/8/2024")
|> should.equal(#(Some(date.literal("2024-07-08")), None, None))
}

pub fn parse_any_time_test() {
tempo.parse_any("13:42:11")
|> should.equal(#(None, Some(time.literal("13:42:11")), None))
Expand Down

0 comments on commit 60db52d

Please sign in to comment.