mirror of https://github.com/snachodog/mybuddy.git
Add USE_24_HOUR_TIME_FORMAT setting (#148)
This commit is contained in:
parent
c5e5589c22
commit
d5dc329cf8
|
@ -1,24 +1,20 @@
|
||||||
# This files adds two new date input formats to support Baby Buddy's frontend
|
from django.conf import settings
|
||||||
# library formats:
|
from django.conf.locale.en import formats
|
||||||
# - %m/%d/%Y %I:%M:%S %p
|
|
||||||
# - %m/%d/%Y %I:%M %p
|
# Override the regular locale settings to support 24 hour time.
|
||||||
#
|
if settings.USE_24_HOUR_TIME_FORMAT:
|
||||||
# The remaining formats come from the base Django formats.
|
DATETIME_FORMAT = 'N j, Y, H:i:s'
|
||||||
#
|
TIME_FORMAT = 'H:i:s'
|
||||||
# See django.cong.locale.en.
|
DATETIME_INPUT_FORMATS = [
|
||||||
DATETIME_INPUT_FORMATS = [
|
'%m/%d/%Y %H:%I:%S' # '10/25/2006 14:30:59'
|
||||||
'%m/%d/%Y %I:%M:%S %p', # '10/25/2006 2:30:59 PM' (new)
|
]
|
||||||
'%m/%d/%Y %I:%M %p', # '10/25/2006 2:30 PM' (new)
|
else:
|
||||||
'%Y-%m-%d %H:%M:%S', # '2006-10-25 14:30:59'
|
# These formats are added to support the locale style of Baby Buddy's
|
||||||
'%Y-%m-%d %H:%M:%S.%f', # '2006-10-25 14:30:59.000200'
|
# frontend library, which uses momentjs.
|
||||||
'%Y-%m-%d %H:%M', # '2006-10-25 14:30'
|
DATETIME_INPUT_FORMATS = [
|
||||||
'%Y-%m-%d', # '2006-10-25'
|
'%m/%d/%Y %I:%M:%S %p', # '10/25/2006 2:30:59 PM'
|
||||||
'%m/%d/%Y %H:%M:%S', # '10/25/2006 14:30:59'
|
'%m/%d/%Y %I:%M %p', # '10/25/2006 2:30 PM'
|
||||||
'%m/%d/%Y %H:%M:%S.%f', # '10/25/2006 14:30:59.000200'
|
]
|
||||||
'%m/%d/%Y %H:%M', # '10/25/2006 14:30'
|
|
||||||
'%m/%d/%Y', # '10/25/2006'
|
# Append all other input formats from the base locale.
|
||||||
'%m/%d/%y %H:%M:%S', # '10/25/06 14:30:59'
|
DATETIME_INPUT_FORMATS.append(formats.DATETIME_INPUT_FORMATS)
|
||||||
'%m/%d/%y %H:%M:%S.%f', # '10/25/06 14:30:59.000200'
|
|
||||||
'%m/%d/%y %H:%M', # '10/25/06 14:30'
|
|
||||||
'%m/%d/%y', # '10/25/06'
|
|
||||||
]
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
from distutils.util import strtobool
|
||||||
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from dotenv import load_dotenv, find_dotenv
|
from dotenv import load_dotenv, find_dotenv
|
||||||
|
@ -166,6 +167,14 @@ LANGUAGES = [
|
||||||
|
|
||||||
USE_L10N = True
|
USE_L10N = True
|
||||||
|
|
||||||
|
# Custom setting that can be used to override the locale-based time set by
|
||||||
|
# USE_L10N _for specific locales_ to use 24-hour format. In order for this to
|
||||||
|
# work with a given locale it must be set at the FORMAT_MODULE_PATH with
|
||||||
|
# conditionals on this setting. See babybuddy/forms/en/formats.py for an example
|
||||||
|
# implementation for the English locale.
|
||||||
|
|
||||||
|
USE_24_HOUR_TIME_FORMAT = strtobool(os.environ.get('USE_24_HOUR_TIME_FORMAT'))
|
||||||
|
|
||||||
FORMAT_MODULE_PATH = ['babybuddy.formats']
|
FORMAT_MODULE_PATH = ['babybuddy.formats']
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue