forked from openlp/openlp
Fix service date formats
This commit is contained in:
parent
18fc78b9fe
commit
1d881e426a
@ -612,18 +612,18 @@ class AdvancedTab(SettingsTab):
|
||||
def generateServiceNameExample(self):
|
||||
preset_is_valid = True
|
||||
if self.serviceNameDay.currentIndex() == 7:
|
||||
time = datetime.now()
|
||||
local_time = datetime.now()
|
||||
else:
|
||||
now = datetime.now()
|
||||
day_delta = self.serviceNameDay.currentIndex() - now.weekday()
|
||||
if day_delta < 0:
|
||||
day_delta += 7
|
||||
time = now + timedelta(days=day_delta)
|
||||
time = time.replace(hour = self.serviceNameTime.time().hour(),
|
||||
local_time = time.replace(hour = self.serviceNameTime.time().hour(),
|
||||
minute = self.serviceNameTime.time().minute())
|
||||
try:
|
||||
service_name_example = format_time(unicode(
|
||||
self.serviceNameEdit.text()))
|
||||
self.serviceNameEdit.text()), local_time)
|
||||
except ValueError:
|
||||
preset_is_valid = False
|
||||
service_name_example = translate('OpenLP.AdvancedTab',
|
||||
|
@ -603,7 +603,7 @@ class ServiceManager(QtGui.QWidget):
|
||||
service_day = Settings().value(
|
||||
u'advanced/default service day', 7).toInt()[0]
|
||||
if service_day == 7:
|
||||
time = datetime.now()
|
||||
local_time = datetime.now()
|
||||
else:
|
||||
service_hour = Settings().value(
|
||||
u'advanced/default service hour', 11).toInt()[0]
|
||||
@ -614,7 +614,7 @@ class ServiceManager(QtGui.QWidget):
|
||||
if day_delta < 0:
|
||||
day_delta += 7
|
||||
time = now + timedelta(days=day_delta)
|
||||
time = time.replace(hour=service_hour, minute=service_minute)
|
||||
local_time = time.replace(hour=service_hour, minute=service_minute)
|
||||
default_pattern = unicode(Settings().value(
|
||||
u'advanced/default service name',
|
||||
translate('OpenLP.AdvancedTab', 'Service %Y-%m-%d %H-%M',
|
||||
@ -622,7 +622,7 @@ class ServiceManager(QtGui.QWidget):
|
||||
'/\\?*|<>\[\]":+\nSee http://docs.python.org/library/'
|
||||
'datetime.html#strftime-strptime-behavior for more '
|
||||
'information.')).toString())
|
||||
default_filename = format_time(default_pattern)
|
||||
default_filename = format_time(default_pattern, local_time)
|
||||
else:
|
||||
default_filename = u''
|
||||
directory = unicode(SettingsManager.get_last_dir(
|
||||
|
@ -35,7 +35,6 @@ import os
|
||||
import re
|
||||
from subprocess import Popen, PIPE
|
||||
import sys
|
||||
import time
|
||||
import urllib2
|
||||
|
||||
from openlp.core.lib.settings import Settings
|
||||
@ -471,16 +470,21 @@ def get_uno_instance(resolver):
|
||||
+ u'urp;StarOffice.ComponentContext')
|
||||
|
||||
|
||||
def format_time(text):
|
||||
def format_time(text, local_time):
|
||||
"""
|
||||
Workaround for Python built-in time formatting fuction time.strftime().
|
||||
|
||||
time.strftime() accepts only ascii characters. This function accepts
|
||||
unicode string and passes individual % placeholders to time.strftime().
|
||||
This ensures only ascii characters are passed to time.strftime().
|
||||
|
||||
``text``
|
||||
The text to be processed.
|
||||
``local_time``
|
||||
The time to be used to add to the string. This is a time object
|
||||
"""
|
||||
def match_formatting(match):
|
||||
return time.strftime(match.group())
|
||||
return local_time.strftime(match.group())
|
||||
return re.sub('\%[a-zA-Z]', match_formatting, text)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user