tools (date_utils): moved date_parse to common.date_utils, because it can be used in frontends
This commit is contained in:
parent
d36f76e7d3
commit
0242772939
6 changed files with 21 additions and 17 deletions
|
|
@ -24,6 +24,7 @@ from sat.core.log import getLogger
|
|||
log = getLogger(__name__)
|
||||
from sat.tools import utils
|
||||
from sat.tools.common import uri as uri_parse
|
||||
from sat.tools.common import date_utils
|
||||
from twisted.internet import defer
|
||||
from twisted.words.protocols.jabber import jid, error
|
||||
from twisted.words.xish import domish
|
||||
|
|
@ -111,7 +112,7 @@ class Events(object):
|
|||
raise exceptions.NotFound(_(u"No event with this id has been found"))
|
||||
|
||||
try:
|
||||
timestamp = utils.date_parse(next(event_elt.elements(NS_EVENT, "date")))
|
||||
timestamp = date_utils.date_parse(next(event_elt.elements(NS_EVENT, "date")))
|
||||
except StopIteration:
|
||||
timestamp = -1
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ from sat.core import exceptions
|
|||
from sat.core.constants import Const as C
|
||||
from sat.tools import xml_tools
|
||||
from sat.tools import utils
|
||||
from sat.tools.common import date_utils
|
||||
from twisted.words.protocols.jabber import jid
|
||||
from twisted.words.protocols.jabber.xmlstream import XMPPHandler
|
||||
from twisted.internet import defer
|
||||
|
|
@ -353,7 +354,7 @@ class PubsubSchema(object):
|
|||
return widget_type, args, kwargs
|
||||
# we convert XMPP date to timestamp
|
||||
try:
|
||||
args[0] = unicode(utils.date_parse(args[0]))
|
||||
args[0] = unicode(date_utils.date_parse(args[0]))
|
||||
except Exception as e:
|
||||
log.warning(_(u"Can't parse date field: {msg}").format(msg=e))
|
||||
return widget_type, args, kwargs
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ from sat.core import exceptions
|
|||
from twisted.internet import defer
|
||||
import os.path
|
||||
from lxml import etree
|
||||
from sat.tools import utils
|
||||
from sat.tools.common import date_utils
|
||||
|
||||
|
||||
PLUGIN_INFO = {
|
||||
|
|
@ -68,8 +68,8 @@ class BugzillaParser(object):
|
|||
for bug in root.xpath('bug'):
|
||||
ticket = {}
|
||||
ticket['id'] = bug.findtext('bug_id')
|
||||
ticket['created'] = utils.date_parse(bug.findtext('creation_ts'))
|
||||
ticket['updated'] = utils.date_parse(bug.findtext('delta_ts'))
|
||||
ticket['created'] = date_utils.date_parse(bug.findtext('creation_ts'))
|
||||
ticket['updated'] = date_utils.date_parse(bug.findtext('delta_ts'))
|
||||
ticket['title'] = bug.findtext('short_desc')
|
||||
reporter_elt = bug.find('reporter')
|
||||
ticket['author'] = reporter_elt.get('name')
|
||||
|
|
@ -103,7 +103,7 @@ class BugzillaParser(object):
|
|||
who = longdesc.find('who')
|
||||
comment = {'id': longdesc.findtext('commentid'),
|
||||
'author_email': who.text,
|
||||
'published': utils.date_parse(longdesc.findtext('bug_when')),
|
||||
'published': date_utils.date_parse(longdesc.findtext('bug_when')),
|
||||
'author': who.get('name', who.text),
|
||||
'content': longdesc.findtext('thetext')}
|
||||
comments.append(comment)
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ from wokkel import disco, iwokkel
|
|||
from zope.interface import implements
|
||||
from sat.tools import utils
|
||||
from sat.tools import stream
|
||||
from sat.tools.common import date_utils
|
||||
import os.path
|
||||
from twisted.words.xish import domish
|
||||
from twisted.words.protocols.jabber import jid
|
||||
|
|
@ -210,7 +211,7 @@ class XEP_0234(object):
|
|||
pass
|
||||
|
||||
try:
|
||||
file_data[u'modified'] = utils.date_parse(next(file_elt.elements(NS_JINGLE_FT, u'date')))
|
||||
file_data[u'modified'] = date_utils.date_parse(next(file_elt.elements(NS_JINGLE_FT, u'date')))
|
||||
except StopIteration:
|
||||
pass
|
||||
|
||||
|
|
|
|||
|
|
@ -21,10 +21,21 @@
|
|||
|
||||
from sat.core.constants import Const as C
|
||||
import datetime
|
||||
from dateutil import parser as dateutil_parser
|
||||
from babel import dates
|
||||
import calendar
|
||||
import time
|
||||
|
||||
|
||||
def date_parse(value):
|
||||
"""Parse a date and return corresponding unix timestamp
|
||||
|
||||
@param value(unicode): date to parse, in any format supported by dateutil.parser
|
||||
@return (int): timestamp
|
||||
"""
|
||||
return calendar.timegm(dateutil_parser.parse(unicode(value)).utctimetuple())
|
||||
|
||||
|
||||
def date_fmt(timestamp, fmt='short', date_only=False, auto_limit=7, auto_old_fmt='short', auto_new_fmt='relative', locale_str=C.DEFAULT_LOCALE):
|
||||
"""format date according to locale
|
||||
|
||||
|
|
|
|||
|
|
@ -25,10 +25,8 @@ from sat.core.constants import Const as C
|
|||
from sat.core.log import getLogger
|
||||
log = getLogger(__name__)
|
||||
import datetime
|
||||
from dateutil import parser as dateutil_parser
|
||||
from twisted.python import procutils
|
||||
import subprocess
|
||||
import calendar
|
||||
import time
|
||||
import sys
|
||||
import random
|
||||
|
|
@ -91,14 +89,6 @@ def xmpp_date(timestamp=None, with_time=True):
|
|||
template = u"{}T{}".format(template_date, template_time) if with_time else template_date
|
||||
return datetime.datetime.utcfromtimestamp(time.time() if timestamp is None else timestamp).strftime(template)
|
||||
|
||||
def date_parse(value):
|
||||
"""Parse a date and return corresponding unix timestamp
|
||||
|
||||
@param value(unicode): date to parse, in any format supported by dateutil.parser
|
||||
@return (int): timestamp
|
||||
"""
|
||||
return calendar.timegm(dateutil_parser.parse(unicode(value)).utctimetuple())
|
||||
|
||||
def generatePassword(vocabulary=None, size=20):
|
||||
"""Generate a password with random characters.
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue