Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

refactor: updateall_day detection logic#2601

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

miketheman
Copy link
Member

Description

Instead of using a particular resolution on an object, which differs betweendatetime.date anddatetime.datetime objects, operate on parent class ofdatetime and convert alldt to timezone-awaredatetime values.

This is also in accordance to the model field being aDateTimeField, so we should always be passing the correctly-created object, instead of adatetime.date(), raisingreceived a naive datetime warnings.

Removes unused constants.

Closes

Closes#2415


Other notes, for fun.

The warnings stem from this little bitty function:

defextract_date_or_datetime(dt):
ifisinstance(dt,datetime.datetime):
returnconvert_dt_to_aware(dt)
returndt

Since the ICS importer is often met with a string that looks like a date-only, like this one:

DTSTART;VALUE=DATE:20160402

the returned type isdatetime.date, not adatetime.datetime.

The change inevents/utils.py drops the warnings, but fails two test cases:

======================================================================FAIL: test_import_event_excludes_ending_day_when_all_day_is_true (events.tests.test_importer.EventsImporterTestCase.test_import_event_excludes_ending_day_when_all_day_is_true)----------------------------------------------------------------------Traceback (most recent call last):  File "/code/events/tests/test_importer.py", line 131, in test_import_event_excludes_ending_day_when_all_day_is_true    self.assertTrue(all_day_event.next_or_previous_time.all_day)AssertionError: False is not true======================================================================FAIL: test_modified_event (events.tests.test_importer.EventsImporterTestCase.test_modified_event)----------------------------------------------------------------------Traceback (most recent call last):  File "/code/events/tests/test_importer.py", line 63, in test_modified_event    self.assertTrue(e.next_or_previous_time.all_day)AssertionError: False is not true

These come from theall_day calculation over here:

# Let's mark those occurrences as 'all-day'.
all_day= (
dt_start.resolution==DATE_RESOLUTIONor
dt_end.resolution==DATE_RESOLUTION
)

which has now been updated.

Instead of using a particular resolution on an object, which differsbetween `datetime.date` and `datetime.datetime` objects, operate onparent class of `datetime` and convert all `dt` to timezone-aware`datetime` values.This is also in accordance to the model field being a `DateTimeField`,so we should always be passing the correctly-created object, instead ofa `datetime.date()`, raising `received a naive datetime` warnings.Removes unused constants.Signed-off-by: Mike Fiedler <miketheman@gmail.com>
@ewdurbinewdurbin merged commit00b4302 intopython:mainSep 30, 2024
3 checks passed
@mikethemanmiketheman deleted the miketheman/fix-naive-date-to-datetime branchNovember 29, 2024 22:28
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@ewdurbinewdurbinewdurbin approved these changes

@JacobCoffeeJacobCoffeeJacobCoffee approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Tests: Silence naive datetime warning spam
3 participants
@miketheman@ewdurbin@JacobCoffee

[8]ページ先頭

©2009-2025 Movatter.jp