Skip to content

Feature/calendar #521

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

pi-myt
Copy link

@pi-myt pi-myt commented Aug 31, 2022

No description provided.

@pi-myt pi-myt marked this pull request as draft August 31, 2022 22:59
@andrewleech
Copy link
Contributor

Nice work pulling this together!

On a structural note, the CI "Check code formatting / build (pull_request)" should normally be resolved by running python3 ./tools/codeformat.py ./python-stdlib/calendar/*.py etc. You'll need pip install black for this.

Similarly eventually could you split the work into 3 commits - one for each package? There's a particular git commit format used here, hopefully it'll be easy enough to see from the git log: https://github.com/micropython/micropython-lib/commits/master

I'll take a look at the code properly when I've got a little more time :-)

@pi-myt
Copy link
Author

pi-myt commented Sep 6, 2022

On a structural note, the CI "Check code formatting / build (pull_request)" should normally be resolved by running python3 ./tools/codeformat.py ./python-stdlib/calendar/*.py etc. You'll need pip install black for this.

Similarly eventually could you split the work into 3 commits - one for each package? There's a particular git commit format used here, hopefully it'll be easy enough to see from the git log: https://github.com/micropython/micropython-lib/commits/master

Thanks Andrew for the extra details. Aiming to get back to this soon to correct the formatting. I was looking at how to break it into 3 commits as there are dependencies between the packages. I could update unittest first, then datetime, then calendar can go in.

@andrewleech
Copy link
Contributor

Yeah no worries. To be clear they don't need to be separate PR's, separate commits on this branch is fine!



# Constants for months referenced later
January = 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good idea to apply micropython.const() to const values

return spacing.join(c.center(colwidth) for c in cols)


EPOCH = 1970
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a problem; on some ports the epoch is 1970, others it's 2000.
Read Damien's summary and micropython/micropython#6873 for background.

Should be able to use something like time.gmtime(0)[0] to retrieve the epoch year.

Copy link
Author

@pi-myt pi-myt Sep 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment, the EPOCH is only used for calendar.timegm(tuple) to calculate the Unix timestamp. I believe this needs to stay as 1970 so the calculated seconds match expectations. (do we have data size or resolution issues?) I get a different number of seconds for the result using the same date/time when testing against Python running on Ubuntu compared to the M5stack and the EPOCH manually set to 1970. (I want to retest to confirm)

I could move the EPOCH values into the function, so it isn't visible to users of Calendar and can't be misused for systems with an EPOCH of 2000. If timegm() is not a required function, we could remove it from Calendar.

Committing a baseline of the code from cPython before
making any suybstantial changes.
Base on cpython calendar functions. This provides most calendar
functions. It does not support locales and some command line
options used to create text calendars.
Added strftime to support new calendar module. strftime does not
support all formatting options. Only enough required for calendar.
Added assertRaisesRegex and assertCountEqual to support
testing the calendar module.
@pi-myt pi-myt marked this pull request as ready for review November 16, 2022 04:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants