|
| 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 --> |
0 commit comments