Пример #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 = ""
    res = run_sql("SELECT DATE_FORMAT(MAX(modification_date),'%Y-%m-%d %H:%i:%s') FROM bibrec", n=1)
    if res:
        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 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
Пример #4
0
def get_latest_datestamp():
    """Get latest datestamp in the database
    Return empty string if no records or latest datestamp in UTC.
    """
    out = ""
    res = run_sql(
        "SELECT DATE_FORMAT(MAX(modification_date),'%Y-%m-%d %H:%i:%s') FROM bibrec",
        n=1)
    if res:
        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_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
Пример #7
0
def get_modification_date(sysno, fmt="%Y-%m-%dT%H:%M:%SZ"):
    """
    Returns the date of last modification for the record 'sysno'.

    @param sysno: the record ID for which we want to retrieve modification date
    @param fmt: output format for the returned date
    @return: modification date of the record
    @rtype: string
    """
    out = ""
    res = run_sql("SELECT DATE_FORMAT(modification_date,'%%Y-%%m-%%d %%H:%%i:%%s') FROM bibrec WHERE id=%s", (sysno,), 1)
    if res and res[0][0]:
        out = localtime_to_utc(res[0][0], fmt)
    return out
Пример #8
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