Skip to content
This repository has been archived by the owner on Apr 26, 2021. It is now read-only.

Added mlbstreamer config option for 24h military time #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

snipem
Copy link
Contributor

@snipem snipem commented Apr 2, 2018

Added option for setting 24 hour time aka military time:

24hourtime

This option can be set by inserting military_time: true into $HOME/.config/mlbstreamer/config.yaml.

If nothing is set or military_time is set to false the default 12 hour formatting is used.

@mattiasa
Copy link
Contributor

mattiasa commented Apr 7, 2018

I think it would be better to use the user's locale settings instead of adding an application-specific parameter for this. Something like this, from https://stackoverflow.com/questions/41864935/how-can-i-check-if-the-current-locale-uses-am-pm-or-24-hour-time?rq=1 should work.

time_format_string = "%H:%M"  # Ex: Sweden
if time.strftime("%p"):  # Checking if the string contains something
    time_format_string = "%I:%M%p"  # Ex: US
return time_format_string

@snipem
Copy link
Contributor Author

snipem commented Apr 7, 2018

This would be the best solution and I was searching for a similar approach.

Unfortunately, on my German installation also the "AM" flag is returned:

~  $ locale
LANG="de_DE.UTF-8"
LC_COLLATE="de_DE.UTF-8"
LC_CTYPE="de_DE.UTF-8"
LC_MESSAGES="de_DE.UTF-8"
LC_MONETARY="de_DE.UTF-8"
LC_NUMERIC="de_DE.UTF-8"
LC_TIME="de_DE.UTF-8"
LC_ALL=
~  $ server
~  $ python3
Python 3.6.4 (default, Mar  3 2018, 20:17:31)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> datetime.datetime.today().strftime("%p")
'AM'

The aforementioned code might not solve the problem and won't determine safely if the users locale does normally show AM or PM times.

@mattiasa
Copy link
Contributor

mattiasa commented Apr 7, 2018

You are of course correct. My bad.

It seems you can use this using babel which comes with its own set of mappings

: lapetus ~ \$ ; LANG=en_US.UTF-8 python
Python 2.7.14 (default, Mar 22 2018, 15:04:47)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import babel.dates
>>> import datetime
>>> babel.dates.format_time(datetime.datetime(year=2018, month=04, day=07, hour=22, minute=10, second=00), format='short')
u'10:10 PM'
>>>
: lapetus ~ \$ ; LANG=de_DE.UTF-8 python
Python 2.7.14 (default, Mar 22 2018, 15:04:47)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import babel.dates
>>> import datetime
>>> babel.dates.format_time(datetime.datetime(year=2018, month=04, day=07, hour=22, minute=10, second=00), format='short')
u'22:10'

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants