Skip to content
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

Cool new date checking syntax? #3

Open
Sternbach-Software opened this issue Jul 11, 2023 · 0 comments
Open

Cool new date checking syntax? #3

Sternbach-Software opened this issue Jul 11, 2023 · 0 comments

Comments

@Sternbach-Software
Copy link
Owner

Sternbach-Software commented Jul 11, 2023

Maybe it would be a big win for readability in complex date logic if we could write something like if (date == 7 of CHESHVAN) instead of
jewishMonth == JewishDate.CHESHVAN && jewishDayOfMonth == 7
(slightly more declarative vs imperative)? This is possible with kotlin infix functions. It could possibly evolve into a DSL. I am wondering where this train of thought could go.

For example, what would be the most concise way of expressing this?

fun isMashivHaruachRecited(jewishCalendar: JewishCalendar): Boolean = jewishCalendar.isBetween(
    JewishDate(jewishCalendar.jewishYear, JewishDate.TISHREI, 22),
    JewishDate(jewishCalendar.jewishYear, JewishDate.NISSAN, 15)
)

fun JewishCalendar.isBetween(
    startDate: JewishDate,
    endDate: JewishDate
) = this > startDate && this < endDate

Maybe

fun isMashivHaruachRecited(jewishCalendar: JewishCalendar): Boolean = jewishCalendar between 22 of TISHREI and 15 of NISSAN

Or

fun isMashivHaruachRecited(jewishCalendar: JewishCalendar): Boolean = jewishCalendar in 22 of TISHREI..15 of NISSAN //can use `until` instead of range operator

As well, this is a common occurence:
day >= 15 && (day <= 22 || !inIsrael && day <= 23)
A range where one of the bounds depends on a variable. Maybe we can do better than an if (day in 15..(if(!inIsrael) 23 else 22))?

Maybe something like day in 15..(22.israel ?: 23)

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

No branches or pull requests

1 participant