Skip to content

Commit

Permalink
- F added even more dates that ChatGPT gave us examples for
Browse files Browse the repository at this point in the history
Co-authored-by: Jay Bazuzi <jay@bazuzi.com>
Co-authored-by: Llewellyn Falco <llewellyn.falco@gmail.com>
  • Loading branch information
3 people committed Jan 13, 2025
1 parent ccf3c9d commit 955d5ff
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.approvaltests.Approvals;
import org.approvaltests.core.Options;
import org.approvaltests.velocity.VelocityApprovals;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import java.util.List;
Expand Down Expand Up @@ -53,4 +54,15 @@ void supportedFormats()
VelocityApprovals.verify(c -> c.put("formats", DateScrubber.getSupportedFormats()),
new Options().forFile().withExtension(".md"));
}

@Disabled("use when new examples are shared at https://github.com/approvals/ApprovalTests.Java/issues/112")
@Test
void textExamples() {
String[] examples = """
05/13/2014 11:50:49 PM
2024-12-18T14:04:46-0500
2025-07-17 14:58:02,123456
""".split("\n");
Approvals.verifyAll("Date scrubbing", examples, this::verifyScrubbing);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
| Oct 13 15:29 | [A-Za-z]{3} \d{2} \d{2}:\d{2} |
| May 13, 2014 11:30:00 PM PST | [a-zA-Z]{3} \d{2}, \d{4} \d{2}:\d{2}:\d{2} [a-zA-Z]{2} [a-zA-Z]{3} |
| 23:30:00 | \d{2}:\d{2}:\d{2} |
| 2014/05/13 16:30:59.786 | \d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}.\d{2}\d |
| 2014/05/13 16:30:59.786 | \d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}(\.\d{3})? |
| 2020-9-10T08:07Z | \d{4}-\d{1,2}-\d{1,2}T\d{1,2}:\d{2}Z |
| 2020-09-10T08:07:89Z | \d{4}-\d{1,2}-\d{1,2}T\d{1,2}:\d{2}:\d{2}Z |
| 2020-09-10T01:23:45.678Z | \d{4}-\d{1,2}-\d{1,2}T\d{1,2}:\d{2}\:\d{2}\.\d{3}Z |
| 20210505T091112Z | \d{8}T\d{6}Z |
| 2024-12-17 | \d{4}-\d{2}-\d{2} |
| 2024-12-18T14:04:46.746130Z | \d{4}-\d{1,2}-\d{1,2}T\d{1,2}:\d{2}:\d{2}(\.\d{1,9})?Z |
| 13/05/2014 23:50:49 | \d{2}[-/.]\d{2}[-/.]\d{4}\s\d{2}:\d{2}(:\d{2})?( (?:pm|am|PM|AM))? |
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ Example: {'date':"[Date1]"}


Scrubbing for 2014/05/13 16:30:59.786:
RegExScrubber[\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}.\d{2}\d]
RegExScrubber[\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}(\.\d{3})?]
Example: {'date':"[Date1]"}


Scrubbing for 2014/05/13 16:30:59:
RegExScrubber[\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}(\.\d{3})?]
Example: {'date':"[Date1]"}


Expand Down Expand Up @@ -106,3 +111,28 @@ RegExScrubber[\d{4}-\d{1,2}-\d{1,2}T\d{1,2}:\d{2}:\d{2}(\.\d{1,9})?Z]
Example: {'date':"[Date1]"}


Scrubbing for 13/05/2014 23:50:49:
RegExScrubber[\d{2}[-/.]\d{2}[-/.]\d{4}\s\d{2}:\d{2}(:\d{2})?( (?:pm|am|PM|AM))?]
Example: {'date':"[Date1]"}


Scrubbing for 13.05.2014 23:50:49:
RegExScrubber[\d{2}[-/.]\d{2}[-/.]\d{4}\s\d{2}:\d{2}(:\d{2})?( (?:pm|am|PM|AM))?]
Example: {'date':"[Date1]"}


Scrubbing for 13-05-2014 23:50:49:
RegExScrubber[\d{2}[-/.]\d{2}[-/.]\d{4}\s\d{2}:\d{2}(:\d{2})?( (?:pm|am|PM|AM))?]
Example: {'date':"[Date1]"}


Scrubbing for 13.05.2014 23:50:
RegExScrubber[\d{2}[-/.]\d{2}[-/.]\d{4}\s\d{2}:\d{2}(:\d{2})?( (?:pm|am|PM|AM))?]
Example: {'date':"[Date1]"}


Scrubbing for 05/13/2014 11:50:49 PM:
RegExScrubber[\d{2}[-/.]\d{2}[-/.]\d{4}\s\d{2}:\d{2}(:\d{2})?( (?:pm|am|PM|AM))?]
Example: {'date':"[Date1]"}


Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public DateScrubber(String pattern, Function1<Integer, String> replacement)
}
public static SupportedFormat[] getSupportedFormats()
{
return new SupportedFormat[]{__("[a-zA-Z]{3} [a-zA-Z]{3} \\d{2} \\d{2}:\\d{2}:\\d{2}", "Tue May 13 16:30:00"),
return new SupportedFormat[]{__("[a-zA-Z]{3} [a-zA-Z]{3} \\d{2} \\d{2}:\\d{2}:\\d{2}",
"Tue May 13 16:30:00"),
__("[a-zA-Z]{3} [a-zA-Z]{3} \\d{2} \\d{2}:\\d{2}:\\d{2} [a-zA-Z]{3,4} \\d{4}",
"Wed Nov 17 22:28:33 EET 2021"),
__("(Mon|Tue|Wed|Thu|Fri|Sat|Sun), \\d{2} (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \\d{4} \\d{2}:\\d{2}:\\d{2} GMT",
Expand All @@ -32,8 +33,8 @@ public static SupportedFormat[] getSupportedFormats()
__("[a-zA-Z]{3} \\d{2}, \\d{4} \\d{2}:\\d{2}:\\d{2} [a-zA-Z]{2} [a-zA-Z]{3}",
"May 13, 2014 11:30:00 PM PST"),
__("\\d{2}:\\d{2}:\\d{2}", "23:30:00"),
__("\\d{4}/\\d{2}/\\d{2} \\d{2}:\\d{2}:\\d{2}.\\d{2}\\d",
"2014/05/13 16:30:59.786"),
__("\\d{4}/\\d{2}/\\d{2} \\d{2}:\\d{2}:\\d{2}(\\.\\d{3})?",
"2014/05/13 16:30:59.786", "2014/05/13 16:30:59"),
__("\\d{4}-\\d{1,2}-\\d{1,2}T\\d{1,2}:\\d{2}Z", "2020-9-10T08:07Z",
"2020-09-9T08:07Z", "2020-09-10T8:07Z", "2020-09-10T08:07Z"),
__("\\d{4}-\\d{1,2}-\\d{1,2}T\\d{1,2}:\\d{2}:\\d{2}Z", "2020-09-10T08:07:89Z"),
Expand All @@ -42,7 +43,16 @@ public static SupportedFormat[] getSupportedFormats()
__("\\d{8}T\\d{6}Z", "20210505T091112Z"),
__("\\d{4}-\\d{2}-\\d{2}", "2024-12-17"),
__("\\d{4}-\\d{1,2}-\\d{1,2}T\\d{1,2}:\\d{2}:\\d{2}(\\.\\d{1,9})?Z",
"2024-12-18T14:04:46.746130Z", "2024-12-18T14:04:46Z", "2024-12-18T14:04:46.746130834Z")};
"2024-12-18T14:04:46.746130Z", "2024-12-18T14:04:46Z",
"2024-12-18T14:04:46.746130834Z"),
__("\\d{2}[-/.]\\d{2}[-/.]\\d{4}\\s\\d{2}:\\d{2}(:\\d{2})?( (?:pm|am|PM|AM))?" ,
"13/05/2014 23:50:49",
"13.05.2014 23:50:49",
"13-05-2014 23:50:49",
"13.05.2014 23:50",
"05/13/2014 11:50:49 PM"
),
};
}
private static SupportedFormat __(String regex, String... examples)
{
Expand Down

0 comments on commit 955d5ff

Please sign in to comment.