Skip to content

Commit

Permalink
feat: add French time support
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Feb 13, 2019
1 parent 0917ffa commit 3b7a8b7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/normalizeInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export default (input: string): string => {

// Remove seconds.
.replace(/([^:]|^)(\d{2}:\d{2}):\d{2}(?:[^:]|$)/g, '$1$2 ')

// Bring French times together
.replace(/(\d+)\s?h\s?(\d+)/i, '$1:$2')
.replace(/,/g, ' ')
.replace(/[.:;] /g, ' ')
.replace(/\s+/g, ' ')
Expand Down
12 changes: 12 additions & 0 deletions test/extract-time/normalizeInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,15 @@ test('removes seconds', (t) => {
test('does not extract time from a concatenation of time-like fragments longer than 3', (t) => {
t.true(normalizeInput('14:00:00:00') === '14:00:00:00');
});

// https://en.wikipedia.org/wiki/Date_and_time_notation_in_France
test('replaces H/h between two time-like fragments with a colon', (t) => {
t.true(normalizeInput('14h10') === '14:10');
t.true(normalizeInput('14H10') === '14:10');
});

// https://en.wikipedia.org/wiki/Date_and_time_notation_in_France
test('pulls together two time-like fragments separated with H/h', (t) => {
t.true(normalizeInput('14 h 10') === '14:10');
t.true(normalizeInput('14 H 10') === '14:10');
});

0 comments on commit 3b7a8b7

Please sign in to comment.