Export to GitHub

google-highly-open-participation-psf - issue #339

Add support for the 'time' module in Shed Skin


Posted on Jan 17, 2008 by Helpful Giraffe

Download and install Shed Skin, and read the included README for usage instructions:

http://shedskin.googlecode.com

Especially read the part about how to implement libraries. Have a look at the lib/ directory for examples of several standard library module implementations.

Add support for the 'time' module. You'll need to have experience with C and C++ to pull this off!

Completion:

Submit a patch as an attachment to this ticket, making sure it works correctly under Windows and Linux.

Task duration: please complete this task within 5 days (120 hours) of claiming it.

Comment #1

Posted on Jan 17, 2008 by Quick Kangaroo

I claim this task.

Comment #2

Posted on Jan 17, 2008 by Happy Camel

good luck!

Comment #3

Posted on Jan 17, 2008 by Helpful Kangaroo

This task is due January 22, 2008 14:30:00 UTC

Comment #4

Posted on Jan 17, 2008 by Quick Kangaroo

I have a question, what should be the default argument for functions like gmtime() or localtime() when I can't use None? Is -sys.maxint-1 good idea?

Comment #5

Posted on Jan 18, 2008 by Happy Camel

no.. :-) I think you can use any int value in lib/time.py, and then provide two C functions, one without arguments and one with an argument, e.g.:

.. localtime() { .. } .. localtime(int secs) { .. }

it's possible this will only work once you move things to lib/, or maybe I have to have another look. you can assume the argument is always/never given for now..

Comment #6

Posted on Jan 18, 2008 by Quick Kangaroo

I was almost sleeping when I wrote that, now I know how to do it. Sorry for asking silly question.

Comment #7

Posted on Jan 19, 2008 by Quick Kangaroo

I have made some progress. I implemented struct_time and mktime(), localtime(), gmtime(), asctime(), ctime(). I have got one problem, these functions expects struct_time as their argument therefore this doesn't work:

time.mktime((2008, 1, 19, 19, 21, 7, 6, 18, 0))

The argument must be struct_time:

time.mktime(time.struct_time((2008, 1, 19, 19, 21, 7, 6, 18, 0)))

Attachments

Comment #8

Posted on Jan 19, 2008 by Happy Camel

good work!

to have mktime also accept tuples, you can just add one with a different type of argument, and the C++ compiler will always pick the right one, like this:

time_t mktime(struct_time *tuple); time_t mktime(tuple2 *tuple);

time_t mktime(struct_time *tuple) { return ::mktime(tuple2tm(tuple)); } time_t mktime(tuple2 *tuple) { .. }

btw, you are probably aware of this, but the return type here should be 'double'.

good luck!

Comment #9

Posted on Jan 20, 2008 by Quick Kangaroo

I have written all functions except tzset(). I am not sure what it should do. Update tzname and timezone?

Attachments

Comment #10

Posted on Jan 20, 2008 by Happy Camel

great, thanks! I added your code to SVN (with some of your tests in unit.py), and marked this task as completed. congratulations :)

about tzset, nevermind this one. it's unix-only anyway.. ;)

some comments: -would it be possible to add some sensible values for accept2dyear, altzone and daylight? -you use a try..catch statement twice - doesn't it work the same without them..?

Comment #11

Posted on Jan 20, 2008 by Quick Kangaroo

The try..catch is useless, I was too much paranoiac. I have added support for 2d years. However I don't know what to do with altzone and daylight. I haven't found any function on linux that would show correctly dst.

Attachments

Comment #12

Posted on Jan 21, 2008 by Happy Camel

nice, thanks. never mind the rest for now.. :)

will commit to SVN tonight.

Comment #13

Posted on Jan 24, 2008 by Happy Camel

hiya,

somehow I didn't see this before. the following code gives a different result when compiled..?

print time.strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S") print time.strptime("2001","%Y")

Comment #14

Posted on Jan 24, 2008 by Quick Kangaroo

It works pretty fine for me. For this file:

import time print time.strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S") print time.strptime("2001","%Y")

I got these outputs: CPython:

[ shedskin-read-only ] $ python pokus.py (2001, 11, 12, 18, 31, 1, 0, 316, -1) (2001, 1, 1, 0, 0, 0, 0, 1, -1)

Shedskin:

[ shedskin-read-only ] $ make run g++ -O3 -pipe -fomit-frame-pointer -I/home/david/programovani/shedskin-read-only/lib /home/david/programovani/shedskin-read-only/lib/builtin.cpp /home/david/programovani/shedskin-read-only/lib/time.cpp pokus.cpp -lgc -o pokus ./pokus (2001, 11, 12, 18, 31, 1, 0, 316, -1) (2001, 1, 1, 0, 0, 0, 0, 1, -1)

Can you specify what's wrong?

Comment #15

Posted on Jan 24, 2008 by Happy Camel

I'm confused :) it's late here, but look at this..:

srepmub@akemi:~/shedskin$ python test.py /usr/lib/python2.5/lib-dynload/time.so (2001, 11, 12, 18, 31, 1, 1, 1, -1) (2001, 1, 1, 0, 0, 0, 1, 1, -1) srepmub@akemi:~/shedskin$ cp test.py .. srepmub@akemi:~/shedskin$ cd .. srepmub@akemi:~$ python test.py /usr/lib/python2.5/lib-dynload/time.so (2001, 11, 12, 18, 31, 1, 0, 316, -1) (2001, 1, 1, 0, 0, 0, 0, 1, -1)

this is in test.py:

import time print time.file print time.strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S") print time.strptime("2001","%Y")

Comment #16

Posted on Jan 24, 2008 by Quick Kangaroo

I am confused, too. There must be something evil in the shedskin directory ;)

Comment #17

Posted on Jan 25, 2008 by Happy Camel

yes, for some reason it uses the datetime.py I had in the shed skin dir.. ! thanks and sorry for bothering you!

Status: Completed

Labels:
C thirdparty coding shedskin Due-20080122.1430 ClaimedBy-h4wk.cz