Skip to content

Commit

Permalink
fix: Ensure we use a common time separator
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewferrier committed Nov 22, 2023
1 parent 13d6b82 commit 0fb4c60
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 4 additions & 3 deletions normfn
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,8 @@ def datetime_prefix(args, non_extension: str, filename: str):
DMY_SEPARATOR_FIRST = r"(?P<dmysep>" + DATE_SEPARATOR + r")"
DMY_SEPARATOR_FOLLOWING = r"(?P=dmysep)"
MY_SEPARATOR = DATE_SEPARATOR
HMS_SEPARATOR = r"[-_.\s]?"
HMS_SEPARATOR_FIRST = r"(?P<hmssep>[-_.\s]?)"
HMS_SEPARATOR_FOLLOWING = r"(?P=hmssep)"
DATE_TIME_SEPARATOR = r"([-_T\s]|\sat\s|,\s)"

REGEX = (
Expand Down Expand Up @@ -459,8 +460,8 @@ def datetime_prefix(args, non_extension: str, filename: str):
+ r"(?P<hour>"
+ HOUR
+ r")"
r"(" + HMS_SEPARATOR + r"(?P<minute>" + MINUTE + r")"
r"(" + HMS_SEPARATOR + r"(?P<second>" + SECOND + r"))?)?)?"
r"(" + HMS_SEPARATOR_FIRST + r"(?P<minute>" + MINUTE + r")"
r"(" + HMS_SEPARATOR_FOLLOWING + r"(?P<second>" + SECOND + r"))?)?)?"
r"(?P<suffix>.*)$"
)

Expand Down
11 changes: 10 additions & 1 deletion tests/Direct/test_Direct_Basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def test_abbr_month_insensitive_hyphen_name(self):
self.assertEqual(1, self.directoryFileCount(self.workingDir))
self.assertEqual('', error)

def test_ensure_common_separator_used(self):
def test_ensure_common_date_separator_used(self):
filename = os.path.join(self.workingDir, 'T 1234 2023-11-22.pdf')
self.touch(filename)
error = self.invokeDirectly([filename])
Expand All @@ -293,6 +293,15 @@ def test_ensure_common_separator_used(self):
self.assertEqual(1, self.directoryFileCount(self.workingDir))
self.assertEqual('', error)

def test_ensure_common_time_separator_used(self):
filename = os.path.join(self.workingDir, 'ABC 2023-11-05T12-13_08.pdf')
self.touch(filename)
error = self.invokeDirectly([filename])
self.assertFalse(os.path.exists(filename))
self.assertTrue(os.path.exists(os.path.join(self.workingDir, '2023-11-05T12-13-ABC _08.pdf')))
self.assertEqual(1, self.directoryFileCount(self.workingDir))
self.assertEqual('', error)

def test_earliest(self):
filename = os.path.join(self.workingDir, 'blah.txt')
self.touch(filename)
Expand Down

0 comments on commit 0fb4c60

Please sign in to comment.