Skip to content

Use timezone.now() for Django CMS timestamps while keeping local times for SourceImage #1107

@coderabbitai

Description

@coderabbitai

Context

In PR #987, a code review suggested using timezone.now() instead of datetime.now() for the Job model's finished_at field. This change was deferred due to the nuanced timezone requirements in the codebase.

Description

The codebase currently has mixed timezone handling:

  • Uses datetime.now() for Job timestamps and other Django CMS operations
  • Project is configured with USE_TZ=False

However, there's a nuanced requirement that needs to be addressed:

SourceImage timestamps (keep as local time)

  • SourceImage timestamps should remain local time only
  • These represent the actual local time when images were captured
  • Converting to UTC would introduce errors for these timestamps
  • No changes needed for SourceImage

Django CMS operations (should use timezone-aware)

  • Job.finished_at and similar Django CMS timestamps should be timezone-aware
  • Web users need to see when jobs started/finished in their local time
  • Currently these are naive datetimes, making it difficult to display correctly across timezones

Proposed Change

  1. Keep SourceImage timestamps as local time (no changes)
  2. Migrate Job.finished_at, Job.started_at, and similar Django CMS fields to use timezone.now()
  3. Consider enabling USE_TZ=True for the Django project, while ensuring SourceImage timestamps remain local
  4. Update any related timestamp handling to maintain the distinction between local-only and timezone-aware timestamps

References

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions