示例#1
0
    def test_localtime_to_utc_uk(self):
        os.environ['TZ'] = 'Europe/London'
        tzset()

        expected = "2012-06-12T15:15:00Z"
        result = dateutils.localtime_to_utc("2012-06-12 16:15:00")
        self.assertEqual(expected, result)

        expected = "2012-12-12T16:15:00Z"
        result = dateutils.localtime_to_utc("2012-12-12 16:15:00")
        self.assertEqual(expected, result)
示例#2
0
def get_latest_datestamp():
    """Get latest datestamp in the database
    Return empty string if no records or latest datestamp in UTC.
    """
    out = CFG_MAX_DATE
    res = run_sql("SELECT " + datetime_format("MAX(modification_date)", False) + " FROM bibrec", n=1)
    if res and res[0][0]:
        out = localtime_to_utc(res[0][0])
    return out
示例#3
0
def get_modification_date(recid):
    """Returns the date of last modification for the record 'recid'.
    Return empty string if no record or modification date in UTC.
    """
    out = ""
    res = run_sql("SELECT " + datetime_format("modification_date") + " FROM bibrec WHERE id=%s", (recid,), 1)
    if res and res[0][0]:
        out = localtime_to_utc(res[0][0])
    return out
示例#4
0
def get_latest_datestamp():
    """Get latest datestamp in the database
    Return empty string if no records or latest datestamp in UTC.
    """
    out = CFG_MAX_DATE
    res = run_sql("SELECT DATE_FORMAT(MAX(modification_date),'%Y-%m-%d %H:%i:%s') FROM bibrec", n=1)
    if res and res[0][0]:
        out = localtime_to_utc(res[0][0])
    return out
示例#5
0
def get_modification_date(recid):
    """Returns the date of last modification for the record 'recid'.
    Return empty string if no record or modification date in UTC.
    """
    out = ""
    res = run_sql("SELECT DATE_FORMAT(modification_date,'%%Y-%%m-%%d %%H:%%i:%%s') FROM bibrec WHERE id=%s", (recid,), 1)
    if res and res[0][0]:
        out = localtime_to_utc(res[0][0])
    return out
示例#6
0
def get_latest_datestamp():
    """Get latest datestamp in the database
    Return empty string if no records or latest datestamp in UTC.
    """
    out = CFG_MAX_DATE
    res = run_sql("SELECT DATE_FORMAT(MAX(modification_date),'%Y-%m-%d %H:%i:%s') FROM bibrec", n=1)
    if res and res[0][0]:
        out = localtime_to_utc(res[0][0])
    return out
示例#7
0
def get_modification_date(recid):
    """Returns the date of last modification for the record 'recid'.
    Return empty string if no record or modification date in UTC.
    """
    out = ""
    res = run_sql("SELECT DATE_FORMAT(modification_date,'%%Y-%%m-%%d %%H:%%i:%%s') FROM bibrec WHERE id=%s", (recid,), 1)
    if res and res[0][0]:
        out = localtime_to_utc(res[0][0])
    return out
示例#8
0
文件: server.py 项目: k3njiy/invenio
def get_earliest_datestamp():
    """Get earliest datestamp in the database
    Return empty string if no records or earliest datestamp in UTC.
    """
    out = CFG_MIN_DATE
    res = run_sql("SELECT " + datetime_format('MIN(creation_date)', False) + "  FROM bibrec", n=1)
    if res and res[0][0]:
        out = localtime_to_utc(res[0][0])
    return out
示例#9
0
def get_earliest_datestamp():
    """Get earliest datestamp in the database
    Return empty string if no records or earliest datestamp in UTC.
    """
    out = CFG_MIN_DATE
    res = run_sql("SELECT " + datetime_format('MIN(creation_date)', False) +
                  "  FROM bibrec",
                  n=1)
    if res and res[0][0]:
        out = localtime_to_utc(res[0][0])
    return out
示例#10
0
def get_modification_date(recid):
    """Returns the date of last modification for the record 'recid'.
    Return empty string if no record or modification date in UTC.
    """
    out = ""
    res = run_sql(
        "SELECT " + datetime_format('modification_date') +
        " FROM bibrec WHERE id=%s", (recid, ), 1)
    if res and res[0][0]:
        out = localtime_to_utc(res[0][0])
    return out
示例#11
0
def get_set_last_update(set_spec=""):
    """
    Returns the last_update of a given set (or of all sets) in UTC
    """
    if set_spec:
        last_update = run_sql("SELECT DATE_FORMAT(MAX(last_updated),'%%Y-%%m-%%d %%H:%%i:%%s') FROM oaiREPOSITORY WHERE setSpec=%s", (set_spec, ))[0][0]
    else:
        last_update = run_sql("SELECT DATE_FORMAT(MAX(last_updated),'%Y-%m-%d %H:%i:%s') FROM oaiREPOSITORY")[0][0]
    if last_update:
        return localtime_to_utc(last_update)
    else:
        return None
示例#12
0
def get_set_last_update(set_spec=""):
    """
    Returns the last_update of a given set (or of all sets) in UTC
    """
    if set_spec:
        last_update = run_sql("SELECT DATE_FORMAT(MAX(last_updated),'%%Y-%%m-%%d %%H:%%i:%%s') FROM oaiREPOSITORY WHERE setSpec=%s", (set_spec, ))[0][0]
    else:
        last_update = run_sql("SELECT DATE_FORMAT(MAX(last_updated),'%Y-%m-%d %H:%i:%s') FROM oaiREPOSITORY")[0][0]
    if last_update:
        return localtime_to_utc(last_update)
    else:
        return None
示例#13
0
文件: server.py 项目: k3njiy/invenio
def get_set_last_update(set_spec=""):
    """
    Returns the last_update of a given set (or of all sets) in UTC
    """
    if set_spec:
        last_update = run_sql("SELECT " + datetime_format('MAX(last_updated)') + """ FROM "oaiREPOSITORY" WHERE setSpec=%s""", (set_spec, ))[0][0]
    else:
        last_update = run_sql("SELECT " + datetime_format('MAX(last_updated)', False) + """ FROM "oaiREPOSITORY" """)[0][0]
    if last_update:
        return localtime_to_utc(last_update)
    else:
        return None
示例#14
0
文件: dblayer.py 项目: SCOAP3/invenio
def get_creation_date(sysno, fmt="%Y-%m-%dT%H:%M:%SZ"):
    """Return the creation date of the record 'sysno'.

    :param sysno: the record ID for which we want to retrieve creation date
    :param fmt: output format for the returned date
    :return: creation date of the record
    @rtype: string
    """
    out = ""
    res = run_sql("SELECT DATE_FORMAT(creation_date, '%%Y-%%m-%%d %%H:%%i:%%s') FROM bibrec WHERE id=%s", (sysno,), 1)
    if res[0][0]:
        out = localtime_to_utc(res[0][0], fmt)
    return out
示例#15
0
def get_creation_date(sysno, fmt="%Y-%m-%dT%H:%M:%SZ"):
    """Return the creation date of the record 'sysno'.

    :param sysno: the record ID for which we want to retrieve creation date
    :param fmt: output format for the returned date
    :return: creation date of the record
    @rtype: string
    """
    out = ""
    res = run_sql(
        "SELECT DATE_FORMAT(creation_date, '%%Y-%%m-%%d %%H:%%i:%%s') FROM bibrec WHERE id=%s",
        (sysno, ), 1)
    if res[0][0]:
        out = localtime_to_utc(res[0][0], fmt)
    return out
示例#16
0
def get_set_last_update(set_spec=""):
    """
    Returns the last_update of a given set (or of all sets) in UTC
    """
    if set_spec:
        last_update = run_sql(
            "SELECT " + datetime_format('MAX(last_updated)') +
            """ FROM "oaiREPOSITORY" WHERE setSpec=%s""", (set_spec, ))[0][0]
    else:
        last_update = run_sql("SELECT " +
                              datetime_format('MAX(last_updated)', False) +
                              """ FROM "oaiREPOSITORY" """)[0][0]
    if last_update:
        return localtime_to_utc(last_update)
    else:
        return None