Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
maubot-ethzlunch
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
isgphys
maubot-ethzlunch
Commits
4ed17251
Commit
4ed17251
authored
5 years ago
by
Tulir Asokan
Browse files
Options
Downloads
Patches
Plain Diff
Add support for AM/PM in US and UK locales
parent
0382b9e8
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
reminder/locale_util.py
+24
-4
24 additions, 4 deletions
reminder/locale_util.py
reminder/locales.py
+10
-4
10 additions, 4 deletions
reminder/locales.py
with
34 additions
and
8 deletions
reminder/locale_util.py
+
24
−
4
View file @
4ed17251
...
...
@@ -13,7 +13,7 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from
typing
import
NamedTuple
,
Union
,
Pattern
,
Dict
,
Type
,
Optional
,
TYPE_CHECKING
from
typing
import
NamedTuple
,
Union
,
Pattern
,
Match
,
Dict
,
Type
,
Optional
,
TYPE_CHECKING
from
datetime
import
datetime
from
abc
import
ABC
,
abstractmethod
import
re
...
...
@@ -73,11 +73,31 @@ class RegexMatcher(Matcher):
def
match
(
self
,
val
:
str
,
start
:
int
=
0
)
->
Optional
[
MatcherReturn
]:
match
=
self
.
regex
.
match
(
val
,
pos
=
start
)
if
match
and
match
.
end
()
>
0
:
return
MatcherReturn
(
params
=
{
key
:
self
.
value_type
(
value
)
for
key
,
value
in
match
.
groupdict
().
items
()
if
value
},
end
=
match
.
end
())
return
self
.
_convert_match
(
match
)
return
None
def
_convert_match
(
self
,
match
:
Match
)
->
MatcherReturn
:
return
MatcherReturn
(
params
=
self
.
_convert_groups
(
match
.
groupdict
()),
end
=
match
.
end
())
def
_convert_groups
(
self
,
groups
:
Dict
[
str
,
str
])
->
'
RelativeDeltaParams
'
:
return
{
key
:
self
.
value_type
(
value
)
for
key
,
value
in
groups
.
items
()
if
value
}
class
TimeMatcher
(
RegexMatcher
):
def
_convert_match
(
self
,
match
:
Match
)
->
MatcherReturn
:
groups
=
match
.
groupdict
()
try
:
meridiem
=
groups
.
pop
(
"
meridiem
"
).
lower
()
except
KeyError
:
meridiem
=
None
params
=
self
.
_convert_groups
(
groups
)
if
meridiem
==
"
pm
"
:
params
[
"
hour
"
]
+=
12
elif
meridiem
==
"
am
"
and
params
[
"
hour
"
]
==
12
:
params
[
"
hour
"
]
=
0
return
MatcherReturn
(
params
=
params
,
end
=
match
.
end
())
class
WeekdayMatcher
(
Matcher
):
regex
:
Pattern
...
...
This diff is collapsed.
Click to expand it.
reminder/locales.py
+
10
−
4
View file @
4ed17251
...
...
@@ -15,7 +15,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from
dateutil.relativedelta
import
MO
,
TU
,
WE
,
TH
,
FR
,
SA
,
SU
from
.locale_util
import
Locales
,
Locale
,
RegexMatcher
,
WeekdayMatcher
from
.locale_util
import
Locales
,
Locale
,
RegexMatcher
,
WeekdayMatcher
,
TimeMatcher
locales
:
Locales
=
{}
...
...
@@ -47,15 +47,21 @@ locales["en_iso"] = Locale(
time
=
RegexMatcher
(
r
"
\s?(?:at\s)?
"
r
"
(?P<hour>\d{2})
"
r
"
[:.](?P<minute>\d{2})
"
r
"
(?:[:.](?P<second>\d{2}))?
"
)
r
"
(?:[:.](?P<second>\d{2}))?
"
)
,
)
time_12_en
=
TimeMatcher
(
r
"
\s?(?:at\s)?
"
r
"
(?P<hour>\d{2})
"
r
"
(?:[:.](?P<minute>\d{2}))?
"
r
"
(?:[:.](?P<second>\d{2}))?
"
r
"
(?:\s(?P<meridiem>a\.?m|p\.?m)\.?)?
"
)
locales
[
"
en_us
"
]
=
locales
[
"
en_iso
"
].
replace
(
name
=
"
English (US)
"
,
name
=
"
English (US)
"
,
time
=
time_12_en
,
date
=
RegexMatcher
(
r
"
(?P<month>\d{1,2})/(?P<day>\d{1,2})(?:/(?P<year>\d{4}))?
"
))
locales
[
"
en_uk
"
]
=
locales
[
"
en_iso
"
].
replace
(
name
=
"
English (UK)
"
,
name
=
"
English (UK)
"
,
time
=
time_12_en
,
date
=
RegexMatcher
(
r
"
(?P<day>\d{1,2})/(?P<month>\d{1,2})(?:/(?P<year>\d{4}))?
"
))
td_sep_fi
=
r
"
(?:[\s,]{1,3}(?:ja\s)?)
"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment