PrimeCalendar provides all the java.util.Calendar functionalities for Persian, Hijri, and Japanese dates

Overview

PrimeCalendar

Android Arsenal Bintray Codacy Badge Awesome Kotlin Badge

PrimeCalendar provides all the java.util.Calendar functionalities for Persian, Hijri, and Japanese dates. PrimeCalendar can be used in every JVM-based projects such as Java/kotlin applications, Android apps, etc.

This library contains three types of calendar systems as well as their conversion to each other.

Calendar System Provider Class Descriptions
Iranian PersianCalendar The most accurate solar calendar in use today.
Islamic HijriCalendar A lunar calendar consisting of 12 lunar months in a year of 354 or 355 days.
Gregorian CivilCalendar The common calendar which is used in most of the world.
Japanese JapaneseCalendar The calendar which is used in Japan.

Download

PrimeCalendar is available on bintray to download using build tools systems.

• Gradle

Add the following lines to your build.gradle file:

repositories {
    jcenter()
}
  
dependencies {
    implementation 'com.aminography:primecalendar:1.3.2'
}

• Maven

Add the following lines to your pom.xml file:

<repositories>
    <repository>
        <id>jcenterid>
        <url>https://jcenter.bintray.com/url>
    repository>
repositories>

<dependencies>
    <dependency>
        <groupId>com.aminographygroupId>
        <artifactId>primecalendarartifactId>
        <version>1.3.2version>
    dependency>
dependencies>

Usage

Calendar objects can be instantiated by the class constructors or using CalendarFactory.

Java

PrimeCalendar calendar = new PersianCalendar();
// or
PrimeCalendar calendar = CalendarFactory.newInstance(CalendarType.PERSIAN);

Kotlin

val calendar = HijriCalendar()
// or
val calendar = CalendarFactory.newInstance(CalendarType.HIJRI)

• Functionalities

Exactly all of the standard Calendar functionalities are implemented in PrimeCalendar including set, add, roll, etc.
To see list of methods and fields, refer to the wiki page.

val civil = CivilCalendar()
civil.set(2019, 5, 17)
println(civil.longDateString)

civil.set(Calendar.DAY_OF_YEAR, 192)
println(civil.longDateString)

civil.add(Calendar.WEEK_OF_YEAR, 14)
println(civil.longDateString)

civil.roll(Calendar.DAY_OF_WEEK, -3)
println(civil.longDateString)

---------------------------
> Monday, 17 June 2019
> Thursday, 11 July 2019
> Thursday, 17 October 2019
> Monday, 14 October 2019

• Date Conversion

Conversion of dates to each other is simply possible by calling the converter methods.

// Converting calendar instance to PersianCalendar:
val persian = calendar.toPersian()

// Converting calendar instance to HijriCalendar:
val hijri = calendar.toHijri()

// Converting calendar instance to CivilCalendar:
val civil = calendar.toCivil()

// Converting calendar instance to JapaneseCalendar:
val japanese = calendar.toJapanese()

Also, it is possible to convert an instance of java.util.Calendar to an instance of PrimeCalendar. For example:

import java.util.Calendar

val calendar = Calendar.getInstance()

// Converting to PersianCalendar:
val persian = calendar.toPersian()

• Kotlin Operators

There is a different way to use get, set, and add methods. Using operators you can do it much simpler. Suppose that the calendar is an instance of PrimeCalendar:

get

val year = calendar.get(Calendar.YEAR)

// equivalent operations:
val year = calendar[Calendar.YEAR]
val year = calendar.year

set

calendar.set(Calendar.MONTH, 7)

// equivalent operations:
calendar[Calendar.MONTH] = 7
calendar.set(Month(7))
calendar.set(7.month)
calendar.month = 7

add

calendar.add(Calendar.DAY_OF_MONTH, 27)

// equivalent operations:
calendar[Calendar.DAY_OF_MONTH] += 27
calendar += DayOfMonth(27)
calendar += 27.dayOfMonth

• Localization

You can localize digits, month names, and week day names by passing locale in constructor. For Persian and Hijri calendars, the default locale is set to Farsi and Arabic respectively.

val persian = PersianCalendar()
println(persian.longDateString)

---------------------------
> پنج‌شنبه، ۲۳ خرداد ۱۳۹۸
val persian = PersianCalendar(Locale.ENGLISH)
println(persian.longDateString)

---------------------------
> Thursday, 23 Khordad 1398

Third Party Libraries

• ThreeTen-Backport (https://www.threeten.org/threetenbp)


Change Log

Version 1.3.2

  • Improving Arabic digits.

Version 1.3.0

  • Adding getter/setter field for all the calendar fields, such as dayOfWeek, hour, etc.
  • Adding date conversion extension functions for java.util.Calendar instances.
  • Adding calendar fields extensions for numbers, e.g. calendar += 27.dayOfMonth

Version 1.2.21

  • Japanese month names and other temporal names are changed.
  • Month constants are added into calendar classes.

License

Copyright 2019 Mohammad Amin Hassani.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Comments
  • Wrong calendar day appears!

    Wrong calendar day appears!

    Hello ,

    I'm using your great calendar 👍 in my business and i'm developing my app using Both of Hijri and Greg. calendars, But look like i'm phasing an issue with the current day appears in the calendar same as suppose today Hijri date is 7 Safar and the day is Thursday but in calendar is appears as today is 6 Safar as green colored cell , Please support if there is any idea to pull 1 day back in the calendar settings , Appreciated.

    Your calendar :

    Screen Shot 2020-09-24 at 4 45 36 PM

    Islamic calendar :

    Screen Shot 1442-02-07 at 4 47 28 PM

    opened by MahmoudAbunaji 7
  • Please remove usages of `jcenter()` Maven repository from your build scripts and migrate your build to other Maven repositories.

    Please remove usages of `jcenter()` Maven repository from your build scripts and migrate your build to other Maven repositories.

    Execution failed for task ':app:dataBindingMergeDependencyArtifactsDebug'.

    Could not resolve all files for configuration ':app:debugCompileClasspath'. Could not find com.aminography:primecalendar:1.2.15. Required by: project :app

    Possible solution:

    • Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
    opened by ayoubdevv 2
  • Manual adjustment of Hijri Calendar

    Manual adjustment of Hijri Calendar

    Since Hijri calendar is lunar, calculations performed well in advance never hold up. This is just the way lunar cycles work and there is no way around that. However, there should be a way in the calendar to manually adjust it by a couple of days or so such that after adjustment, the calendar is in accordance with the latest information.

    For instance, hijriCalendar.adjust(+2) should make it so that 2 Muharram corresponded to 2 July originally, it should now correspond to 4 July instead. (or something similar).

    This is an essential part that is missing fron almost all implementations of the Hijri calendar system so far.

    opened by hafizmdyasir 0
  • leap year issue

    leap year issue

    HI. i create a calendar from this library. But when I take the date as millisecond from 30 esfand, it is equal to 1 farvardin 1774081800000 I checked and found out that 1404 is not a leap year at all. The year 1403 is a leap year. The library is wrong in leap years

    Maybe this method is wrong : https://github.com/aminography/PrimeCalendar/blob/c3918445a6210697ec02aaaaf6eff169bb05d9a0/library/src/main/java/com/aminography/primecalendar/persian/PersianCalendarUtils.kt#L281

    opened by SudoDios 0
  • Suggestion

    Suggestion

    Hi, I have a suggestion to add event feature

    Now that all the systems are connected to the Internet, I suggest you implement the connection with the calendar APIs, in this good source as well. I use this service a lot myself https://apieco.ir/api/farsicalendar

    Provides good information such as events by day and receive events in solar, lunar and Gregorian mode.

    opened by mehrdadashtari 1
Releases(v1.7.0)
  • v1.7.0(Dec 29, 2021)

    What's Changed

    • Set default value of dateAdjustingOffset to 1 for HijriCalendar.

    Full Changelog: https://github.com/aminography/PrimeCalendar/compare/v1.6.0...v1.7.0

    Source code(tar.gz)
    Source code(zip)
  • v1.6.0(Dec 29, 2021)

    What's Changed

    • Rollback to use threetenbp, plus adding the ability to shift Hijri dates. by @aminography in https://github.com/aminography/PrimeCalendar/pull/10

    Full Changelog: https://github.com/aminography/PrimeCalendar/compare/v1.5.0...v1.6.0

    Source code(tar.gz)
    Source code(zip)
  • v1.5.0(Dec 29, 2021)

    What's Changed

    • Removed dependency to threetenbp. by @aminography in https://github.com/aminography/PrimeCalendar/pull/9

    Full Changelog: https://github.com/aminography/PrimeCalendar/compare/v1.4.1...v1.5.0

    Source code(tar.gz)
    Source code(zip)
  • v1.4.1(Dec 29, 2021)

    What's Changed

    • Considered timeZone and locale in calendar conversion. by @aminography in https://github.com/aminography/PrimeCalendar/pull/8

    Full Changelog: https://github.com/aminography/PrimeCalendar/compare/v1.4.0...v1.4.1

    Source code(tar.gz)
    Source code(zip)
  • v1.4.0(Dec 28, 2021)

Owner
Amin Hassani
Android Developer ⚡
Amin Hassani
An android library which provides a compact calendar view much like the one used in google calenders.

CompactCalendarView CompactCalendarView is a simple calendar view which provides scrolling between months. It's based on Java's Date and Calendar clas

SundeepK 1.5k Dec 9, 2022
CalEF (Calendar Entry Formatter) : Select an entry in Android-Kalender and send/share the entry's content as human readable text.

CalEF (Calendar Entry Formatter) Select an entry in Android-Kalender and send/share the entry's content as human readable text. Usually calendar entri

k3b 6 Aug 17, 2022
Standalone Android widget for picking a single date from a calendar view.

TimesSquare for Android Standalone Android widget for picking a single date from a calendar view. Usage Include CalendarPickerView in your layout XML.

Square 4.4k Dec 20, 2022
A better calendar for Android

Caldroid Caldroid is a fragment that display calendar with dates in a month. Caldroid can be used as embedded fragment, or as dialog fragment. User ca

Roomorama 1.4k Jan 5, 2023
Android calendar view (like card)

android-calendar-card (Google Play Demo) Android calendar view (like card) Simple and easy to modify Author: Michał Szwarc #CalendarCardPager License

Michał Szwarc 473 Nov 10, 2022
📅 Material Design Calendar compatible with API 11+

> Prettier and simpler Material Design CalendarView MaterialCalendarView is a prettier and simpler, material design calendar that allows full customiz

BlackBox Vision 365 Nov 21, 2022
📅 Material Design Calendar compatible with API 11+

> Prettier and simpler Material Design CalendarView MaterialCalendarView is a prettier and simpler, material design calendar that allows full customiz

BlackBox Vision 366 Jan 1, 2023
A lightweight monthly calendar view for Android, fully written in Kotlin. Designed to meet the minimum demands for typical calendars.

Light Calendar View A lightweight monthly calendar view for Android, fully written in Kotlin. Designed to meet the minimum demands for typical calenda

Recruit Marketing Partners Co.,Ltd 444 Dec 9, 2022
A TimelineView that will help you create event timelines in apps just like the Google Calendar DayView

TimelineView A TimelineView that will help you create event timelines in apps just like the Google Calendar DayView A library that allows you to creat

Amit Krishna A 10 May 12, 2022
JetCalendarView - A calendar library for Jetpack Compose

JetCalendar WIP 2022 Hit Refresh! Calendar view ❤️ Jetpack Compose License Copyr

Anmol Verma 8 Aug 17, 2022
Fully customizable Calendar/DatePicker for Android/Kotlin

AMCalendar - Android Date (Range) Picker AMCalendar is a fully customisable widget for picking dates and ranges based on the native Calendar. It's an

null 6 Oct 18, 2022
Appleader707 1 Aug 9, 2022
A material-styled android view that provisions picking of a date, time & recurrence option, all from a single user-interface.

SublimePicker A customizable view that provisions picking of a date, time & recurrence option, all from a single user-interface. You can also view 'Su

Vikram 2.3k Jan 4, 2023
Amazing Dynamic Time UI :clock1030: :hourglass: and More

FlatTimeCollection Amazing Dynamic Time UI ?? ⌛ for Android To help you design your Layout. it is Not just a UI, But it contains a CountDownTimer with

Anas Altair 72 Apr 28, 2022
A customizable, easy-to-use, and functional circular time range picker library for Android

A customizable, easy-to-use, and functional circular time range picker library for Android. Use this library to mimic Apple's iOS or Samsung's bedtime picker.

Joery Droppers 251 Dec 30, 2022
Android interval timer app using compose + compose navigation, dagger hilt, room, kotlin coroutines + flow and mvvm design pattern.

What's InTime? ⏳ InTime is an interval timer application using android jetpack components and a long running service. The purpose of this project is t

P. 46 Oct 10, 2022
Android DatePicker with month and year build with Compose UI

Compose Date Picker - Select month and year Compose Date Picker tries to offer you the year and month pickers which you can customize for your require

Doğuş Teknoloji 48 Jan 7, 2023
Android Compose wheel picker library based on LazyColumn in vertical and LazyRow in horizontal.

About Android Compose wheel picker library based on LazyColumn in vertical and LazyRow in horizontal. Gradle Sample Default Item size Unfocused count

null 6 Dec 22, 2022
Nepali Date Picker library in Jetpack compose for android with Date conversion from BS to AD and vice-versa

Nepali Date picker Converter - Re in Compose This is a re-work of Nepali Date Picker Converter in jetpack compose and kotlin. English Locale Nepali Lo

Kiran Gyawali 4 Dec 23, 2022