2014-03-10 01:18:05 -04:00
|
|
|
# Author: Nic Wolfe <nic@wolfeden.ca>
|
|
|
|
# URL: http://code.google.com/p/sickbeard/
|
|
|
|
#
|
2014-05-23 08:37:22 -04:00
|
|
|
# This file is part of SickRage.
|
2014-03-10 01:18:05 -04:00
|
|
|
#
|
2014-05-23 08:37:22 -04:00
|
|
|
# SickRage is free software: you can redistribute it and/or modify
|
2014-03-10 01:18:05 -04:00
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
2014-05-23 08:37:22 -04:00
|
|
|
# SickRage is distributed in the hope that it will be useful,
|
2014-03-10 01:18:05 -04:00
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2014-05-23 08:37:22 -04:00
|
|
|
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
import datetime
|
|
|
|
import locale
|
|
|
|
import functools
|
|
|
|
|
|
|
|
import sickbeard
|
|
|
|
|
|
|
|
date_presets = ('%Y-%m-%d',
|
|
|
|
'%a, %Y-%m-%d',
|
|
|
|
'%A, %Y-%m-%d',
|
|
|
|
'%y-%m-%d',
|
|
|
|
'%a, %y-%m-%d',
|
|
|
|
'%A, %y-%m-%d',
|
|
|
|
'%m/%d/%Y',
|
|
|
|
'%a, %m/%d/%Y',
|
|
|
|
'%A, %m/%d/%Y',
|
|
|
|
'%m/%d/%y',
|
|
|
|
'%a, %m/%d/%y',
|
|
|
|
'%A, %m/%d/%y',
|
|
|
|
'%m-%d-%Y',
|
|
|
|
'%a, %m-%d-%Y',
|
|
|
|
'%A, %m-%d-%Y',
|
|
|
|
'%m-%d-%y',
|
|
|
|
'%a, %m-%d-%y',
|
|
|
|
'%A, %m-%d-%y',
|
|
|
|
'%m.%d.%Y',
|
|
|
|
'%a, %m.%d.%Y',
|
|
|
|
'%A, %m.%d.%Y',
|
|
|
|
'%m.%d.%y',
|
|
|
|
'%a, %m.%d.%y',
|
|
|
|
'%A, %m.%d.%y',
|
|
|
|
'%d-%m-%Y',
|
|
|
|
'%a, %d-%m-%Y',
|
|
|
|
'%A, %d-%m-%Y',
|
|
|
|
'%d-%m-%y',
|
|
|
|
'%a, %d-%m-%y',
|
|
|
|
'%A, %d-%m-%y',
|
|
|
|
'%d.%m.%Y',
|
|
|
|
'%a, %d.%m.%Y',
|
|
|
|
'%A, %d.%m.%Y',
|
|
|
|
'%d.%m.%y',
|
|
|
|
'%a, %d.%m.%y',
|
|
|
|
'%A, %d.%m.%y',
|
|
|
|
'%d. %b %Y',
|
|
|
|
'%a, %d. %b %Y',
|
|
|
|
'%A, %d. %b %Y',
|
|
|
|
'%d. %b %y',
|
|
|
|
'%a, %d. %b %y',
|
|
|
|
'%A, %d. %b %y',
|
|
|
|
'%d. %B %Y',
|
|
|
|
'%a, %d. %B %Y',
|
|
|
|
'%A, %d. %B %Y',
|
|
|
|
'%d. %B %y',
|
|
|
|
'%a, %d. %B %y',
|
|
|
|
'%A, %d. %B %y',
|
|
|
|
'%b %d, %Y',
|
|
|
|
'%a, %b %d, %Y',
|
|
|
|
'%A, %b %d, %Y',
|
|
|
|
'%B %d, %Y',
|
|
|
|
'%a, %B %d, %Y',
|
|
|
|
'%A, %B %d, %Y'
|
2014-03-25 01:57:24 -04:00
|
|
|
)
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
time_presets = ('%I:%M:%S %p',
|
|
|
|
'%H:%M:%S'
|
2014-03-25 01:57:24 -04:00
|
|
|
)
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
# helper class
|
|
|
|
class static_or_instance(object):
|
|
|
|
def __init__(self, func):
|
|
|
|
self.func = func
|
|
|
|
|
|
|
|
def __get__(self, instance, owner):
|
|
|
|
return functools.partial(self.func, instance)
|
|
|
|
|
2014-03-25 01:57:24 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
# subclass datetime.datetime to add function to display custom date and time formats
|
|
|
|
class sbdatetime(datetime.datetime):
|
|
|
|
has_locale = True
|
2014-05-17 03:56:41 -04:00
|
|
|
ORIG_LC_TIME = locale.LC_TIME
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-05-26 17:32:47 -04:00
|
|
|
# display Time in SickRage Format
|
2014-03-10 01:18:05 -04:00
|
|
|
@static_or_instance
|
2014-03-25 01:57:24 -04:00
|
|
|
def sbftime(self, dt=None, show_seconds=False, t_preset=None):
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-05-18 14:21:18 -04:00
|
|
|
try:locale.setlocale(locale.LC_TIME, self.ORIG_LC_TIME)
|
|
|
|
except:pass
|
2014-05-10 08:02:05 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
try:
|
|
|
|
if sbdatetime.has_locale:
|
|
|
|
locale.setlocale(locale.LC_TIME, 'us_US')
|
|
|
|
except:
|
|
|
|
sbdatetime.has_locale = False
|
2014-05-18 14:21:18 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
strt = ''
|
|
|
|
try:
|
|
|
|
if self is None:
|
|
|
|
if dt is not None:
|
|
|
|
if t_preset is not None:
|
|
|
|
strt = dt.strftime(t_preset)
|
|
|
|
elif show_seconds:
|
|
|
|
strt = dt.strftime(sickbeard.TIME_PRESET_W_SECONDS)
|
|
|
|
else:
|
|
|
|
strt = dt.strftime(sickbeard.TIME_PRESET)
|
|
|
|
else:
|
|
|
|
if t_preset is not None:
|
|
|
|
strt = self.strftime(t_preset)
|
|
|
|
elif show_seconds:
|
|
|
|
strt = self.strftime(sickbeard.TIME_PRESET_W_SECONDS)
|
|
|
|
else:
|
|
|
|
strt = self.strftime(sickbeard.TIME_PRESET)
|
|
|
|
finally:
|
|
|
|
try:
|
|
|
|
if sbdatetime.has_locale:
|
2014-05-17 03:56:41 -04:00
|
|
|
locale.setlocale(locale.LC_TIME, self.ORIG_LC_TIME)
|
2014-03-10 01:18:05 -04:00
|
|
|
except:
|
|
|
|
sbdatetime.has_locale = False
|
2014-05-18 14:21:18 -04:00
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
return strt
|
|
|
|
|
2014-05-26 17:32:47 -04:00
|
|
|
# display Date in SickRage Format
|
2014-03-10 01:18:05 -04:00
|
|
|
@static_or_instance
|
2014-03-25 01:57:24 -04:00
|
|
|
def sbfdate(self, dt=None, d_preset=None):
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-05-10 08:02:05 -04:00
|
|
|
try:
|
2014-05-17 03:56:41 -04:00
|
|
|
locale.setlocale(locale.LC_TIME, self.ORIG_LC_TIME)
|
2014-05-10 08:02:05 -04:00
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
strd = ''
|
|
|
|
try:
|
|
|
|
if self is None:
|
|
|
|
if dt is not None:
|
|
|
|
if d_preset is not None:
|
|
|
|
strd = dt.strftime(d_preset)
|
|
|
|
else:
|
|
|
|
strd = dt.strftime(sickbeard.DATE_PRESET)
|
|
|
|
else:
|
|
|
|
if d_preset is not None:
|
|
|
|
strd = self.strftime(d_preset)
|
|
|
|
else:
|
|
|
|
strd = self.strftime(sickbeard.DATE_PRESET)
|
|
|
|
finally:
|
2014-05-18 14:21:18 -04:00
|
|
|
|
|
|
|
try:
|
|
|
|
locale.setlocale(locale.LC_TIME, self.ORIG_LC_TIME)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
return strd
|
|
|
|
|
2014-05-26 17:32:47 -04:00
|
|
|
# display Datetime in SickRage Format
|
2014-03-10 01:18:05 -04:00
|
|
|
@static_or_instance
|
2014-03-25 01:57:24 -04:00
|
|
|
def sbfdatetime(self, dt=None, show_seconds=False, d_preset=None, t_preset=None):
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-05-10 08:02:05 -04:00
|
|
|
try:
|
2014-05-17 03:56:41 -04:00
|
|
|
locale.setlocale(locale.LC_TIME, self.ORIG_LC_TIME)
|
2014-05-10 08:02:05 -04:00
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
strd = ''
|
|
|
|
try:
|
|
|
|
if self is None:
|
|
|
|
if dt is not None:
|
|
|
|
if d_preset is not None:
|
|
|
|
strd = dt.strftime(d_preset)
|
|
|
|
else:
|
|
|
|
strd = dt.strftime(sickbeard.DATE_PRESET)
|
|
|
|
try:
|
|
|
|
if sbdatetime.has_locale:
|
|
|
|
locale.setlocale(locale.LC_TIME, 'us_US')
|
|
|
|
except:
|
|
|
|
sbdatetime.has_locale = False
|
|
|
|
if t_preset is not None:
|
|
|
|
strd += u', ' + dt.strftime(t_preset)
|
|
|
|
elif show_seconds:
|
|
|
|
strd += u', ' + dt.strftime(sickbeard.TIME_PRESET_W_SECONDS)
|
|
|
|
else:
|
|
|
|
strd += u', ' + dt.strftime(sickbeard.TIME_PRESET)
|
|
|
|
else:
|
|
|
|
if d_preset is not None:
|
|
|
|
strd = self.strftime(d_preset)
|
|
|
|
else:
|
|
|
|
strd = self.strftime(sickbeard.DATE_PRESET)
|
|
|
|
try:
|
|
|
|
if sbdatetime.has_locale:
|
|
|
|
locale.setlocale(locale.LC_TIME, 'us_US')
|
|
|
|
except:
|
|
|
|
sbdatetime.has_locale = False
|
|
|
|
if t_preset is not None:
|
|
|
|
strd += u', ' + self.strftime(t_preset)
|
|
|
|
elif show_seconds:
|
|
|
|
strd += u', ' + self.strftime(sickbeard.TIME_PRESET_W_SECONDS)
|
|
|
|
else:
|
|
|
|
strd += u', ' + self.strftime(sickbeard.TIME_PRESET)
|
|
|
|
finally:
|
|
|
|
try:
|
|
|
|
if sbdatetime.has_locale:
|
2014-05-17 03:56:41 -04:00
|
|
|
locale.setlocale(locale.LC_TIME, self.ORIG_LC_TIME)
|
2014-03-10 01:18:05 -04:00
|
|
|
except:
|
|
|
|
sbdatetime.has_locale = False
|
2014-05-18 14:21:18 -04:00
|
|
|
|
2014-05-26 17:32:47 -04:00
|
|
|
return strd
|