Show
Ignore:
Timestamp:
06/01/05 10:05:34 (19 years ago)
Author:
jerome
Message:

A positive or negative offset can be added to the special keywords in dumpykota's date filtering options

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/storage.py

    r2268 r2276  
    601601        now = DateTime.now()     
    602602        nameddates = ('yesterday', 'today', 'now', 'tomorrow') 
    603         if ((startdate.lower() in nameddates) or startdate.isdigit()) and \ 
    604            ((enddate.lower() in nameddates) or enddate.isdigit()) :  
    605             datedict = { "start" : startdate, "end" : enddate }     
    606             for limit in datedict.keys() : 
    607                 dateval = datedict[limit] 
    608                 if dateval in nameddates : 
     603        datedict = { "start" : startdate.lower(), "end" : enddate.lower() }     
     604        for limit in datedict.keys() : 
     605            dateval = datedict[limit] 
     606            for name in nameddates : 
     607                if dateval.startswith(name) : 
     608                    try : 
     609                        offset = int(dateval[len(name):]) 
     610                    except :     
     611                        offset = 0 
     612                    dateval = dateval[:len(name)]     
    609613                    if limit == "start" : 
    610614                        if dateval == "yesterday" : 
    611                             dateval = (now - 1).Format("%Y%m%d000000") 
     615                            dateval = (now - 1 + offset).Format("%Y%m%d000000") 
    612616                        elif dateval == "today" : 
    613                             dateval = now.Format("%Y%m%d000000") 
     617                            dateval = (now + offset).Format("%Y%m%d000000") 
    614618                        elif dateval == "now" : 
    615                             dateval = now.Format("%Y%m%d%H%M%S") 
     619                            dateval = (now + offset).Format("%Y%m%d%H%M%S") 
    616620                        else : # tomorrow 
    617                             dateval = (now + 1).Format("%Y%m%d000000") 
     621                            dateval = (now + 1 + offset).Format("%Y%m%d000000") 
    618622                    else : 
    619623                        if dateval == "yesterday" : 
    620                             dateval = (now - 1).Format("%Y%m%d235959") 
     624                            dateval = (now - 1 + offset).Format("%Y%m%d235959") 
    621625                        elif dateval == "today" : 
    622                             dateval = now.Format("%Y%m%d235959") 
     626                            dateval = (now + offset).Format("%Y%m%d235959") 
    623627                        elif dateval == "now" : 
    624                             dateval = now.Format("%Y%m%d%H%M%S") 
     628                            dateval = (now + offset).Format("%Y%m%d%H%M%S") 
    625629                        else : # tomorrow 
    626                             dateval = (now + 1).Format("%Y%m%d235959") 
    627                          
     630                            dateval = (now + 1 + offset).Format("%Y%m%d235959") 
     631                    break 
     632                     
     633            if not dateval.isdigit() : 
     634                dateval = None 
     635            else :     
    628636                lgdateval = len(dateval) 
    629637                if lgdateval == 4 : 
     
    661669                except :     
    662670                    dateval = None 
    663                 datedict[limit] = dateval     
    664             (start, end) = (datedict["start"], datedict["end"]) 
    665             if start > end : 
    666                 (start, end) = (end, start) 
    667             return (start, end)     
    668         else :             
    669             return (None, None) 
     671            datedict[limit] = dateval     
     672        (start, end) = (datedict["start"], datedict["end"]) 
     673        if start > end : 
     674            (start, end) = (end, start) 
     675        return (start, end)     
    670676         
    671677def openConnection(pykotatool) :