brick / date-time

Date and time library for PHP
MIT License
323 stars 29 forks source link

Custom calendars #17

Open bmarwell opened 4 years ago

bmarwell commented 4 years ago

Hi,

Is there are way to add custom calendars? I know in java this is possible.

If not, well, this is a feature request. 😉

BenMorel commented 4 years ago

Hi, no there isn't at the moment. Could you please describe your use case?

bmarwell commented 4 years ago

Hi @BenMorel, sure.

Use case description

Please take a look at this project: https://github.com/fisharebest/webtrees/

Webtrees is a online Genealogy software. That means, you input the date of an individuals birth, death, some-other-event in the date which was mentioned in the SOURCES. That said, you'd put in George Washingtons Birthday in the Julian Calendar, but when he died the gregorian calendar was in use.

user story

As a user, I'd expect to see the Proleptic calendar date of Washingtons birth (if I wanted to), and the age should also be calculated in the gregorian/proleptic style.

technical background

We have a webtrees slack. A new version 2.0.0 (based on laravel) is on its way, but wouldn't include brick/date-time. I wanted to investigate if this library adds some benefits over the existing implementation.

As you seem to know PHP and Java (including JSR310), I think you could explain the benefits of this implementation in the slack. But maybe I am mistaken, and JSR310 does not support the calendars I mentioned, because it is not as extensible as I remembered.

Regards, Ben

bmarwell commented 4 years ago

Other things to consider:

None of the other libraries can support this: icecave/chrono and briannesbitt/Carbon for example, but also cakePHP's port are unable to have a calendar implemented. This library is the only one that could have a calendar interface extracted, which I hope is similar to JSR310's interface.

BenMorel commented 4 years ago

Hi @bmhm,

Thank you for your use case description.

I'm open to adding support for custom calendars; however, I'm not familiar with other calendars at all, so unless I'm extensively briefed on the matter, and get enough time to work on it, I'm currently unable to help.

Would you be interested in opening a PR to add support for these calendars?

bmarwell commented 4 years ago

Phew. I looked into your code and I realized two things.

So I'm probably not able to help. ☚ī¸

BenMorel commented 4 years ago

If you give me some examples of how a different calendar affects the behaviour of existing classes such as LocalDate etc., I might be able to get a better understanding of the situation!

bmarwell commented 4 years ago

There are a lot of examples on the web. I'm going to collect some of them here in multiple edits.

BenMorel commented 4 years ago

If custom calendars just meant a different date for today (with the same year-month-day concept), this would probably be quite easy to implement.

But from what I can see by quickly browsing your links, calendars like the Japanese one do not seem to use the same concept of year-month-day, you'd need an additional era field that does not have any meaning in our calendar, so it's a totally different beast and I'm not sure whether this is in the scope of this project (at least at the moment).

bmarwell commented 4 years ago

Yes that's what I meant I'm the first place. I do not know of any library which could provide this. But yours is based on jsr310 and would be somewhat easy to extend to the same functionality.

Yes, some calendar systems have a different number of months or not the concept of months at all.

BenMorel commented 4 years ago

Although very similar, the project is not a direct port of JSR-310, it misses some concepts such as these calendars, and integrates others that, AFAIK, are missing in java.time, such as LocalDateRange, and timecop-inspired clocks.

I'm not against integrating these calendars at some point in the future, but I won't be able to investigate this further at the moment. I'll keep this issue open, though, if someone wants to jump in and work on a PR!

bmarwell commented 4 years ago

Thanks. I'll try to find someone to work with on this. Maybe we could even start a branch together at some point.