adriank / ObjectPath

The agile query language for semi-structured data
http://objectpath.org
MIT License
380 stars 93 forks source link

date and time from string #79

Closed TuSKan closed 5 years ago

TuSKan commented 5 years ago

Hi adrian, Thank you very much for building this awesome package.

I would like to calculate the age from the object below:

{
     "born": "1980-05-11 04:22:33"
}

It's possible on functions on _ObjectPath/objectpath/utils/timeutils.p_y to accept strings, with adding a format parameter?

adriank commented 5 years ago

Here you go.

TuSKan commented 5 years ago

Wow!!!! Thank you very much for being so blazing fast to do this new feature. I really appreciate that!

TuSKan commented 5 years ago

I don't know what I miss here, but don't work for me.

This works fine

from objectpath.utils.timeutils import  dateTime
dateTime(["1980-05-11 04:22:33", "%Y-%m-%d %H:%M:%S"])

But this don't work, return NoneType

from objectpath import *
Tree({}).execute('dateTime(["1980-05-11 04:22:33", "%Y-%m-%d %H:%M:%S"])')
adriank commented 5 years ago

dateTime("1980-05-11 04:22:33", "%Y-%m-%d %H:%M:%S")

Greetings, Adrian Kalbarczyk

http://kalbarczyk.co

On Tue, Dec 4, 2018 at 11:45 PM Rener Castro notifications@github.com wrote:

I don't know what I miss here, but don't work for me.

This works fine

from objectpath.utils.timeutils import dateTime dateTime(["1980-05-11 04:22:33", "%Y-%m-%d %H:%M:%S"])

But this don't work, return NoneType

from objectpath import * Tree({}).execute('dateTime(["1980-05-11 04:22:33", "%Y-%m-%d %H:%M:%S"])')

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/adriank/ObjectPath/issues/79#issuecomment-444288629, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKycnBJqFhIsKYvo3n9dOG9W5bAvdaxks5u1vsdgaJpZM4Y_kx6 .

TuSKan commented 5 years ago

It works, Thank you very much!!!

TuSKan commented 5 years ago

In ObjectPath/objectpath/utils/timeutils.py line 37 _years = round910(days/356) should not be 365 ?

def age(date, reference=None, lang="en"):
  if reference is None:
    reference = now()
  td = reference - date  #TimeDelta

  days = float(td.days)
  langIsPL = lang == "pl"
  if days:
    years = round9_10(days/356)
   ...
adriank commented 5 years ago

It should.

On Wed, 5 Dec 2018 at 02:55 Rener Castro notifications@github.com wrote:

In ObjectPath/objectpath/utils/timeutils.py line 37 years = round9_10(days/356) should not be 365 ?

def age(date, reference=None, lang="en"): if reference is None: reference = now() td = reference - date #TimeDelta

days = float(td.days) langIsPL = lang == "pl" if days: years = round9_10(days/356) ...

— You are receiving this because you were assigned.

Reply to this email directly, view it on GitHub https://github.com/adriank/ObjectPath/issues/79#issuecomment-444329146, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKycmDQ2sf-6FySJrKKw9-Kzu1T22tdks5u1yeQgaJpZM4Y_kx6 .

-- Greetings, Adrian Kalbarczyk

http://kalbarczyk.co