Skip to content

Commit

Permalink
Merge pull request #10 from plone/issue-8-localization
Browse files Browse the repository at this point in the history
Issue 8 localization
  • Loading branch information
jensens committed Apr 26, 2015
2 parents 0ece960 + cbe7093 commit da0259a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Changelog
2.2.5 (unreleased)
------------------

- Nothing changed yet.
- Preventing AM/PM issue when some locales are set.
This fix https://github.com/plone/plone.app.form/issues/8
[keul]


2.2.4 (2014-01-27)
Expand Down
2 changes: 1 addition & 1 deletion plone/app/form/widgets/datecomponents.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def result(self, date=None,

for x in ('AM', 'PM'):
d={'id': x, 'value': x, 'selected': None}
if x==p and not default:
if x==p.upper() and not default:
d['selected']=1
ampm.append(d)

Expand Down
17 changes: 17 additions & 0 deletions plone/app/form/widgets/datecomponents.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,23 @@ test is run.
>>> parseDate(parts)
(2499, '12', '31', '00', '00')

Now testing if Python env localization will not affects the AM/PM behavior of the
view (preventing regression of issue https://github.com/plone/plone.app.form/issues/8).
The EN_us locale will not suffer of the issue while other (DE_de or IT_it) do.

>>> import locale
>>> default_locale = locale.getlocale()
>>> testdate = DateTime.DateTime('2015/04/17 09:00:00')
>>> locale.setlocale(locale.LC_ALL, "EN_us")
'EN_us'
>>> view.result(testdate, use_ampm=True)['ampm']
[{'selected': None, 'id': '--', 'value': 'AM'}, {'selected': 1, 'id': 'AM', 'value': 'AM'}, {'selected': None, 'id': 'PM', 'value': 'PM'}]
>>> locale.setlocale(locale.LC_ALL, "IT_it")
'IT_it'
>>> view.result(testdate, use_ampm=True)['ampm']
[{'selected': None, 'id': '--', 'value': 'AM'}, {'selected': 1, 'id': 'AM', 'value': 'AM'}, {'selected': None, 'id': 'PM', 'value': 'PM'}]
>>> dummy = locale.setlocale(locale.LC_ALL, default_locale)

un-monkey patch
>>> DateTime.DateTime.localZone = realLocalZone
>>> datecomponents.PLONE_CEILING = DateTime.DateTime(2500, 0)
Expand Down

0 comments on commit da0259a

Please sign in to comment.