Giter Club home page Giter Club logo

primecalendar's Introduction

PrimeCalendar

Android Arsenal mavenCentral 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 MavenCentral to download using build tools systems.

• Gradle

Add the following lines to your build.gradle file:

dependencies {
    implementation 'com.aminography:primecalendar:1.7.0'
}

• Maven

Add the following lines to your pom.xml file:

<dependencies>
    <dependency>
        <groupId>com.aminography</groupId>
        <artifactId>primecalendar</artifactId>
        <version>1.7.0</version>
    </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.4.0

  • Migrating to MavenCentral.

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.

primecalendar's People

Contributors

aminography avatar varunasingh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

primecalendar's Issues

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

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.

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:

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.

Custom fonts?

How to set custom fonts for all elements (day, weekday name, month name)?

Set Month Does Not Work Properly...

Hi
When you set the month value for the calendar, it starts from 0.
In my opinion, if it starts from 1, it will help more...

Exp:

fun main() {
val calendarPrimary = CalendarFactory.newInstance(CalendarType.CIVIL)
calendarPrimary.set(year = 2023, month = 8, dayOfMonth = 17)

val millis = calendarPrimary.timeInMillis

println(millis)

val calendarSecondary = CalendarFactory.newInstance(type = CalendarType.CIVIL)
calendarSecondary.timeInMillis = millis

println(calendarSecondary.shortDateString)

}

Out :

1694933393081
2023/09/17
(23, 9, 17)

Finally, thanks for PrimeCalendar ❤

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.