Git Product home page Git Product logo

Comments (5)

appsplash99 avatar appsplash99 commented on May 28, 2024

Hey Hello there,
I am new to opensource but not to python, however, i might be wrong but here's why the above issue might have occured:

The source code related to the readdate is located in this file: sciris/sciris/sc_utils.py.
In line 1237 readdate function is defined, its implementation is such that it uses datetime module and looks for a format in the below dictinary called formats_to_try :

formats_to_try = {
    'date':           '%Y-%m-%d', # 2020-03-21
    'date-alpha':     '%Y-%b-%d', # 2020-Mar-21
    'date-numeric':   '%Y%m%d',   # 20200321
    'datetime':       '%Y-%m-%d %H:%M:%S',    # 2020-03-21 14:35:21
    'datetime-alpha': '%Y-%b-%d %H:%M:%S',    # 2020-Mar-21 14:35:21
    'default':        '%Y-%m-%d %H:%M:%S.%f', # 2020-03-21 14:35:21.23483
    'ctime':          '%a %b %d %H:%M:%S %Y', # Sat Mar 21 23:09:29 2020
    }

In our issue case, we are supplying the '%T' for '15:48:05' but the code is unable to find it.

Fixing Issue: What we can do is instead of using '%T' we can use '%H:%M:%S' as:

sc.readdate("Tue 2020-09-29 15:48:05", dateformat='%a %Y-%m-%d %H:%M:%S')

which is available in the formats_to_try dictionary.

I hope this helps and if not please do let me know πŸ˜„.
And sorry for bad editing

from sciris.

cliffckerr avatar cliffckerr commented on May 28, 2024

Hi @appsplash99 , thank you so much for your comment! This indeed does fix it. %T is a valid time code in some cases (here, git log) but not for Python. But the real issue is that the way readdate() is written, it doesn't pass on exceptions. In this case the exception strptime() raises is quite clear, ValueError: 'T' is a bad directive in format '%a %Y-%m-%d %T'. This issue will be fixed in the next release of Sciris, hopefully in a few weeks.

from sciris.

appsplash99 avatar appsplash99 commented on May 28, 2024

Can i do it?

from sciris.

cliffckerr avatar cliffckerr commented on May 28, 2024

Sure, go ahead! Thank you!

from sciris.

appsplash99 avatar appsplash99 commented on May 28, 2024

Wait! I don't think there's any error here:
I think our application of using%T is inapplicable.

The reason why:
Even if i use %T with datetime as it is , we still get an error:

INPUT:
datetime_str = '09/19/18 10:55:26'
datetime_object = datetime.strptime(datetime_str, '%m/%d/%y %T')
print(datetime_object) 

OUTPUT:
ValueError: 'T' is a bad directive in format '%m/%d/%y %T'

So, you can use%X instead which is Locale’s appropriate time representation. - 21:30:00 (en_US); 21:30:00 (de_DE)

Another Fix:

sc.readdate("Tue 2020-09-29 15:48:05", dateformat='%a %Y-%m-%d %X')

Hope this Helps πŸ˜„ πŸ‘

from sciris.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.