×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Jul 2008
    Location
    Amiens, France
    Posts
    9

    Problems with negative dates (before 01/01/1970)

    Hi,

    I use an other contact database than the default one. When I want to store a negative float in a field of type 'date' (i.e. a date before 01/01/1970), this is what I get : "ValueError: illegal field type or value".

    Is it normal? I don't understand because I can store a such a date in the default database (I didn't try by a PyS60 script, but only by the contacts menu). My code seems good (I hope!) because I can store a positive date without problems or warnings...

    Thanks by advance!

    See You,
    squalbee.

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: Problems with negative dates (before 01/01/1970)

    Quote Originally Posted by squalbee View Post
    Hi,

    I use an other contact database than the default one. When I want to store a negative float in a field of type 'date' (i.e. a date before 01/01/1970), this is what I get : "ValueError: illegal field type or value".

    Is it normal? I don't understand because I can store a such a date in the default database (I didn't try by a PyS60 script, but only by the contacts menu). My code seems good (I hope!) because I can store a positive date without problems or warnings...

    Thanks by advance!

    See You,
    squalbee.
    hi squalbee
    check this link
    may it help you.

  3. #3
    Registered User
    Join Date
    Jul 2008
    Location
    Amiens, France
    Posts
    9

    Re: Problems with negative dates (before 01/01/1970)

    Hi,

    In the link you told me, they use date but only with positive values, if I put a negative value, I have the same problem...

    This is a little example of my problem, with this code:
    Code:
    import contacts, time
    
    def test_date():
        # open a new empty contacts database
        db = contacts.open('test_database', 'n')
    
        # add one contact
        contact = db.add_contact()
        contact.add_field('last_name', 'A')
        contact.add_field('date', 1.0)
        contact.commit()
        # print contact
        name = contact.find(u'last_name')[0].value
        date = contact.find(type=u'date')[0].value
        print 'name=%s'%name
        print 'date=%s'%time.strftime('%d/%m/%Y-%Hh%Mm%Ss', time.localtime(date))
    
        # add the second contact
        contact = db.add_contact()
        contact.add_field('last_name', 'B')
        contact.add_field('date', -1.0) # same problem if I put 0.0
        contact.commit()
        # print contact
        name = contact.find(u'last_name')[0].value
        date = contact.find(type=u'date')[0].value
        print 'name=%s'%name
        print 'date=%s'%time.strftime('%d/%m/%Y-%Hh%Mm%Ss', time.localtime(date))
    
    test_date()
    The first contact is added and printed on screen, but the second one has a problem on the line
    Code:
    contact.add_field('date', -1.0) --> self._contact.add_field(template_ID,** kw) ValueError: illegal field type or value
    But in my default contact list, I can have people with a negative date! Why can't I do it by myself with a python script?
    Any idea? If this little script works on your phone, could you tell it to me?

    Thanks.
    squalbee

  4. #4
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: Problems with negative dates (before 01/01/1970)

    hi squalbee
    first of all sorry for replying late now i think all the dates and time in our PyS60 are according to unix timestamps which is from 1970 that may cause the problem in your case.

    Enjoy Pythoning
    Gaba88

  5. #5
    Registered User
    Join Date
    Jul 2008
    Location
    Amiens, France
    Posts
    9

    Re: Problems with negative dates (before 01/01/1970)

    Hi,

    I'm sorry too for my late replies! But after your first answer, I tried some stuffs with the file you gave me, and now I was in a friend's home

    Why can I do that
    Code:
    import time
    print time.strftime("%d/%m/%Y - %Hh%Mm%Ss", time.localtime(-100000.0))
    >> 30/12/1969 - 22h13m20s
    (so, python can handle dates before 01/01/1970 = Unix time) and not that?
    Code:
    ...
    contact.add_field('date', -1.0)
    >> ValueError: illegal field type or value
    Someone know if it's a known problem about "add_field" with "date" type or maybe I write something wrong... Maybe Python is not the right language for me! (what a pity, I'm just learning it).

    Thanks,
    squalbee.

  6. #6
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: Problems with negative dates (before 01/01/1970)

    hi squalbee
    why dont you convert the date into proper format before adding it to the database.

    Enjoy Pythoning
    Gaba88

  7. #7
    Registered User
    Join Date
    Jul 2008
    Location
    Amiens, France
    Posts
    9

    Re: Problems with negative dates (before 01/01/1970)

    Hi,

    I believe the proper format is float... That's what I do. According to you, which format have I to use? Do you think a negative float is not good? If it's the case I don't understand why.

    Thanks,
    squalbee.
    PS: I will not be able to touch a computer for maybe one day, so don't worry if I don't reply quickly.

  8. #8
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: Problems with negative dates (before 01/01/1970)

    Quote Originally Posted by squalbee View Post
    Hi,

    I believe the proper format is float... That's what I do. According to you, which format have I to use? Do you think a negative float is not good? If it's the case I don't understand why.
    hi squalbee
    what actually i mean is you in your earlier post said that you can use negative dates in python using the following code.
    Code:
    import time
    print time.strftime("%d/%m/%Y - %Hh%Mm%Ss", time.localtime(-100000.0))
    >> 30/12/1969 - 22h13m20s
    then why dont you convert the date first and then add it to the database.

    Hope you get this time
    Enjoy Pythoning
    Gaba88

  9. #9
    Registered User
    Join Date
    Jul 2008
    Location
    Amiens, France
    Posts
    9

    Re: Problems with negative dates (before 01/01/1970)

    Hi,

    Thanks gaba88.
    My example was only here to show you that it was possible to handle dates before Unix time with Python. The format for "add_filed" is float.

    Sorry, but for 2 days I will not be able to touch my computer, one of my friend will marry.

    squalbee.
    PS: sorry for my english, maybe I'm not very polite or something else because of my bad english.

Similar Threads

  1. Problems about maemo 4.0.1 SDK installation.
    By fgg_maemo in forum General Development Questions
    Replies: 3
    Last Post: 2008-10-07, 14:26
  2. Several problems with NMIT 4.1 MMS
    By jtalviva in forum General Messaging
    Replies: 0
    Last Post: 2006-03-10, 11:03
  3. Several problems with NMIT 4.1
    By jtalviva in forum Mobile Java Tools & SDKs
    Replies: 0
    Last Post: 2006-03-10, 10:59
  4. Problems with Nokia carkit CK-1W
    By Batunas in forum General Development Questions
    Replies: 1
    Last Post: 2004-02-09, 18:18

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×