Skip to content

Commit 8b04ab2

Browse files
committed
. dt documentation for date scrubber
1 parent 66fd05b commit 8b04ab2

File tree

3 files changed

+87
-7
lines changed

3 files changed

+87
-7
lines changed

date_scrubber_test.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package approvals_test
22

33
import (
44
"fmt"
5+
"strings"
56
"testing"
67

78
approvals "github.com/approvals/go-approval-tests"
@@ -38,7 +39,7 @@ func TestGetDateScrubber(t *testing.T) {
3839
}
3940

4041
func TestExampleForDocumentation(t *testing.T) {
41-
// begin-snippet: scrub-date-example
42+
// begin-snippet: scrub_date_example
4243
scrubber, err := approvals.GetDateScrubberFor("00:00:00")
4344
if err != nil {
4445
t.Error(err)
@@ -47,9 +48,15 @@ func TestExampleForDocumentation(t *testing.T) {
4748
// end-snippet
4849
}
4950

50-
// @Test
51-
// void supportedFormats()
52-
// {
53-
// VelocityApprovals.verify(c -> c.put("formats", DateScrubber.getSupportedFormats()),
54-
// new Options().forFile().withExtension(".md"));
55-
// }
51+
func TestSupportedFormats(t *testing.T) {
52+
formats := approvals.GetSupportedFormats()
53+
54+
table := "| Example Date | RegEx Pattern |\n"
55+
table += "| :-------------------- | :----------------------- |\n"
56+
57+
for _, f := range formats {
58+
table += fmt.Sprintf("| %s | `%s` |\n", f.Examples[0], strings.ReplaceAll(f.Regex, "|", `\|`))
59+
}
60+
61+
approvals.VerifyString(t, table, approvals.Options().ForFile().WithExtension(".md"))
62+
}

docs/how_to/ScrubDates.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# How to scrub dates
2+
3+
<!-- toc -->
4+
## Contents
5+
6+
* [Supported formats](#supported-formats)<!-- endToc -->
7+
8+
The easiest way to scrub a date is by calling
9+
10+
<!-- snippet: scrub_date_example -->
11+
<a id='snippet-scrub_date_example'></a>
12+
```go
13+
scrubber, err := approvals.GetDateScrubberFor("00:00:00")
14+
if err != nil {
15+
t.Error(err)
16+
}
17+
approvals.VerifyString(t, "created at 03:14:15", approvals.Options().WithScrubber(scrubber))
18+
```
19+
<sup><a href='/date_scrubber_test.go#L42-L48' title='Snippet source file'>snippet source</a> | <a href='#snippet-scrub_date_example' title='Start of snippet'>anchor</a></sup>
20+
<!-- endSnippet -->
21+
22+
which will produce
23+
24+
<!-- snippet: date_scrubber_test.TestExampleForDocumentation.approved.txt -->
25+
<a id='snippet-date_scrubber_test.TestExampleForDocumentation.approved.txt'></a>
26+
```txt
27+
created at [Date1]
28+
```
29+
<sup><a href='/testdata/date_scrubber_test.TestExampleForDocumentation.approved.txt#L1-L1' title='Snippet source file'>snippet source</a> | <a href='#snippet-date_scrubber_test.TestExampleForDocumentation.approved.txt' title='Start of snippet'>anchor</a></sup>
30+
<!-- endSnippet -->
31+
32+
## Supported formats
33+
34+
<!-- include: date_scrubber_test.TestSupportedFormats.approved.md -->
35+
| Example Date | RegEx Pattern |
36+
| :-------------------- | :----------------------- |
37+
| Tue May 13 16:30:00 | `[a-zA-Z]{3} [a-zA-Z]{3} \d{2} \d{2}:\d{2}:\d{2}` |
38+
| Wed Nov 17 22:28:33 EET 2021 | `[a-zA-Z]{3} [a-zA-Z]{3} \d{2} \d{2}:\d{2}:\d{2} [a-zA-Z]{3,4} \d{4}` |
39+
| Wed, 21 Oct 2015 07:28:00 GMT | `(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` |
40+
| Tue May 13 2014 23:30:00.789 | `[a-zA-Z]{3} [a-zA-Z]{3} \d{2} \d{4} \d{2}:\d{2}:\d{2}.\d{3}` |
41+
| Tue May 13 16:30:00 -0800 2014 | `[a-zA-Z]{3} [a-zA-Z]{3} \d{2} \d{2}:\d{2}:\d{2} -\d{4} \d{4}` |
42+
| 13 May 2014 23:50:49,999 | `\d{2} [a-zA-Z]{3} \d{4} \d{2}:\d{2}:\d{2},\d{3}` |
43+
| Oct 13 15:29 | `[A-Za-z]{3} \d{2} \d{2}:\d{2}` |
44+
| 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}` |
45+
| 23:30:00 | `\d{2}:\d{2}:\d{2}` |
46+
| 2014/05/13 16:30:59.786 | `\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}(\.\d{3})?` |
47+
| 2020-9-10T08:07Z | `\d{4}-\d{1,2}-\d{1,2}T\d{1,2}:\d{2}Z` |
48+
| 2020-09-10T08:07:89Z | `\d{4}-\d{1,2}-\d{1,2}T\d{1,2}:\d{2}:\d{2}Z` |
49+
| 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` |
50+
| 20210505T091112Z | `\d{8}T\d{6}Z` |
51+
| 2024-12-17 | `\d{4}-\d{2}-\d{2}` |
52+
| 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` |
53+
| 13/05/2014 23:50:49 | `\d{2}[-/.]\d{2}[-/.]\d{4}\s\d{2}:\d{2}(:\d{2})?( (?:pm\|am\|PM\|AM))?` |
54+
<!-- endInclude -->
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
| Example Date | RegEx Pattern |
2+
| :-------------------- | :----------------------- |
3+
| Tue May 13 16:30:00 | `[a-zA-Z]{3} [a-zA-Z]{3} \d{2} \d{2}:\d{2}:\d{2}` |
4+
| Wed Nov 17 22:28:33 EET 2021 | `[a-zA-Z]{3} [a-zA-Z]{3} \d{2} \d{2}:\d{2}:\d{2} [a-zA-Z]{3,4} \d{4}` |
5+
| Wed, 21 Oct 2015 07:28:00 GMT | `(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` |
6+
| Tue May 13 2014 23:30:00.789 | `[a-zA-Z]{3} [a-zA-Z]{3} \d{2} \d{4} \d{2}:\d{2}:\d{2}.\d{3}` |
7+
| Tue May 13 16:30:00 -0800 2014 | `[a-zA-Z]{3} [a-zA-Z]{3} \d{2} \d{2}:\d{2}:\d{2} -\d{4} \d{4}` |
8+
| 13 May 2014 23:50:49,999 | `\d{2} [a-zA-Z]{3} \d{4} \d{2}:\d{2}:\d{2},\d{3}` |
9+
| Oct 13 15:29 | `[A-Za-z]{3} \d{2} \d{2}:\d{2}` |
10+
| 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}` |
11+
| 23:30:00 | `\d{2}:\d{2}:\d{2}` |
12+
| 2014/05/13 16:30:59.786 | `\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}(\.\d{3})?` |
13+
| 2020-9-10T08:07Z | `\d{4}-\d{1,2}-\d{1,2}T\d{1,2}:\d{2}Z` |
14+
| 2020-09-10T08:07:89Z | `\d{4}-\d{1,2}-\d{1,2}T\d{1,2}:\d{2}:\d{2}Z` |
15+
| 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` |
16+
| 20210505T091112Z | `\d{8}T\d{6}Z` |
17+
| 2024-12-17 | `\d{4}-\d{2}-\d{2}` |
18+
| 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` |
19+
| 13/05/2014 23:50:49 | `\d{2}[-/.]\d{2}[-/.]\d{4}\s\d{2}:\d{2}(:\d{2})?( (?:pm\|am\|PM\|AM))?` |

0 commit comments

Comments
 (0)