How to implement the Persian calendar

Is there an implementation of Persian calendar DatePicker in JavaFx?

No Persian chronology to use on DatePicker to create a Persian calendar

+5
source share
2 answers

Now I have developed a ready-to-use calendar picker that also offers a Persian calendar. Initially, he was inspired by the good work of Christian Schudt, but was completely rewritten and expanded. Just download my Time4J library -v4.20 (or later, available on Maven) and use this code demo :

 CalendarPicker<PersianCalendar> picker = picker.persianWithSystemDefaults(); picker.setLengthOfAnimations(Duration.seconds(0.7)); picker.setShowInfoLabel(true); picker.setLocale(new Locale("fa", "IR")); picker.setShowWeeks(true); picker.setCellCustomizer( (cell, column, row, model, date) -> { if (CellCustomizer.isWeekend(column, model)) { cell.setStyle("-fx-background-color: #FFE0E0;"); cell.setDisable(true); } } ); 

You can also set other properties, such as minimum and maximum dates. Here is an example image using Farsi and a localized weekly model for Iran. You can navigate through all Persian months, years or decades (by clicking on the header) or go to the current date (by clicking on the footer).

enter image description here

+3
source

As indicated in the docs, you can set your calendar system using the ObjectProperty<Chronology> DatePicker . The method you need to do is

 public final void setChronology(Chronology value) 

Since there is no Persian / Iranian calendar system installed by default (only the hiraj system is implemented), you must write your own:

" Adding new calendars The set of available chronologies can be expanded by applications. Adding a new calendar system requires writing a chronology implementation, ChronoLocalDate and Era. Most of the logic specific to the calendar system will be implemented in the ChronoLocalDate implementation. The chronology implementation acts like a factory.

To enable the opening of additional chronologies, ServiceLoader is used. The file should be added to the META-INF / services directory with the name "java.time.chrono.Chronology", which lists the implementation classes. For more information about loading a service, see ServiceLoader. To search by identifier or type calendarType, the system is first displayed, in which calendars are displayed, and then the calendar calendars of the application.

Each timeline must define a timeline identifier that is unique to the system. If the chronology is a calendar system defined by the CLDR specification, then the calendar type is a concatenation of the CLDR type and, if applicable, the CLDR variant,

Implementation Requirements: This interface must be implemented with care to ensure that other classes work correctly. All implementations that can be created must be final, immutable, and thread safe. Subclasses should be Serializable where possible. "Source: https://docs.oracle.com/javase/8/docs/api/java/time/chrono/Chronology.html?is-external=true

+1
source

All Articles