Skip to content

Add static calendar() method to jdatetime.date for displaying monthly calendar#177

Open
Peyman20122 wants to merge 3 commits into
slashmili:mainfrom
Peyman20122:main
Open

Add static calendar() method to jdatetime.date for displaying monthly calendar#177
Peyman20122 wants to merge 3 commits into
slashmili:mainfrom
Peyman20122:main

Conversation

@Peyman20122
Copy link
Copy Markdown

@Peyman20122 Peyman20122 commented May 10, 2026

Hello dear engineer

Summary

This PR adds a new static method calendar() to the jdatetime.date class. It displays a monthly calendar (week-based table) for any given Shamsi (Jalali) year and month, similar to the Unix cal command or Python's calendar module.

Motivation

Currently, jdatetime provides date conversion and formatting but lacks a built‑in way to visualize a whole month as a weekly grid. This feature is useful for many Persian applications (CLI tools, scheduling widgets, etc.) and reduces boilerplate code for users.

Changes

  • Added @staticmethod calendar(year=None, month=None, locale=None) to jdatetime.date.
  • If year and month are omitted, it shows the current month.
  • The method respects the thread‑local locale (Persian/English) for month names and weekday headers.
  • Returns a multi‑line string (not printed directly) for flexibility.
  • Handles leap years correctly (Esfand can have 30 days).
  • Input validation (year range, month range) similar to the constructor.

Example usage

import jdatetime

# Current month calendar
print(jdatetime.date.calendar())

# Specific month (English)
print(jdatetime.date.calendar(1405, 2, locale='en_US'))

# Persian calendar
jdatetime.set_locale('fa_IR')
print(jdatetime.date.calendar(1405, 2))

Output example (English)

   Ordibehesht 1405
Sa Su Mo Tu We Th Fr
    1  2  3  4  5  6
 7  8  9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31

Additional notes

· The weekday headers assume Saturday = 0 (week starts on Saturday), consistent with jdatetime.date.weekday().
· The method does not depend on external libraries (e.g., numpy, hijridate).
· I have tested the method with various inputs and locales.

Peyman20122 and others added 3 commits May 10, 2026 16:37
feat: add static calender method to jdatetime.date class
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.

1 participant