com.ghasemkiani.util.icu
Class PersianCalendar

java.lang.Object
  extended bycom.ibm.icu.util.Calendar
      extended bycom.ghasemkiani.util.icu.PersianCalendar
All Implemented Interfaces:
java.lang.Cloneable, PersianCalendarConstants, java.io.Serializable

public class PersianCalendar
extends com.ibm.icu.util.Calendar
implements PersianCalendarConstants

This is an arithmetic implementation of the Persian Calendar (also known as the Iranian or Jalali Calendar) based on the calendar framework of ICU4J (IBM's International Components for Unicode for Java), version 3.2.

ICU4J is copyright International Business Machines Corporation (IBM). Please see the file icu4j_3_2_license.html included with this software package for information about ICU4J license.

An astronomical version of the Persian Calendar may be implemented in a future release.

Usage Example

The following code snippet shows how to use the PersianCalendar class:

        import java.util.Date;
        import com.ibm.icu.util.TimeZone;
        import com.ibm.icu.util.ULocale;
        import com.ibm.icu.text.DateFormat;
        import com.ghasemkiani.util.icu.PersianCalendar;
        // ...

        PersianCalendar pc = new PersianCalendar(TimeZone.getTimeZone("Asia/Tehran"));
        DateFormat df = pc.getDateTimeFormat(DateFormat.FULL, DateFormat.DEFAULT, new ULocale("fa", "IR", ""));
        String result = df.format(new Date());
        // ...
        

Some possible results are shown below:

Locale Formatted String
فارسی جمعه، ۷ اسفند ۱۳۸۳ ۱۲:۰۰:۳۹
فارسی (افغانستان) جمعه، ۷ حوت ۱۳۸۳ ۱۲:۰۰:۳۹
العربية الجمعة, ٧ إسفند, ١٣٨٣ ١٢:٠٠:٣٩ م
English Friday, Esfand 7, 1383 12:00:39 PM
Français vendredi 7 Esfand 1383 12:00:39
Deutsch Freitag, 7. Esfand 1383 12:00:39
Русский 7 Эсфанд 1383 г. 12:00:39
Türkçe 07 Isfend 1383 Cuma 12:00:39
Esperanto vendredo, 7-a de esfando 1383 12:00:39

Version:
2.1
Author:
Ghasem Kiani
See Also:
Serialized Form

Field Summary
static int AH
          After Hijra Era.
static int BH
          Before Hijra Era.
 
Fields inherited from class com.ibm.icu.util.Calendar
AM, AM_PM, APRIL, AUGUST, DATE, DAY_OF_MONTH, DAY_OF_WEEK, DAY_OF_WEEK_IN_MONTH, DAY_OF_YEAR, DECEMBER, DOW_LOCAL, DST_OFFSET, ERA, EXTENDED_YEAR, FEBRUARY, FRIDAY, HOUR, HOUR_OF_DAY, JANUARY, JULIAN_DAY, JULY, JUNE, MARCH, MAY, MILLISECOND, MILLISECONDS_IN_DAY, MINUTE, MONDAY, MONTH, NOVEMBER, OCTOBER, PM, SATURDAY, SECOND, SEPTEMBER, SUNDAY, THURSDAY, TUESDAY, UNDECIMBER, WEDNESDAY, WEEK_OF_MONTH, WEEK_OF_YEAR, WEEKDAY, WEEKEND, WEEKEND_CEASE, WEEKEND_ONSET, YEAR, YEAR_WOY, ZONE_OFFSET
 
Fields inherited from interface com.ghasemkiani.util.PersianCalendarConstants
ABAN, AZAR, BAHMAN, DEY, ESFAND, FARVARDIN, KHORDAD, MEHR, MORDAD, ORDIBEHESHT, SHAHRIVAR, TIR
 
Constructor Summary
PersianCalendar()
          Constructs a Persian calendar with the default time zone and locale.
PersianCalendar(java.util.Date date)
          Constructs a Persian calendar with the default time zone and locale and sets its time to the specified date-time.
PersianCalendar(int year, int month, int date)
          Constructs a Persian calendar with the default time zone and locale and sets its time to the specified date.
PersianCalendar(int year, int month, int date, int hour, int minute, int second)
          Constructs a Persian calendar with the default time zone and locale and sets its time to the specified time.
PersianCalendar(java.util.Locale aLocale)
          Constructs a Persian calendar with the default time zone and the specified locale.
PersianCalendar(com.ibm.icu.util.TimeZone zone)
          Constructs a Persian calendar with the specified time zone and the default locale.
PersianCalendar(com.ibm.icu.util.TimeZone zone, java.util.Locale aLocale)
          Constructs a Persian calendar with the specified time zone and locale.
PersianCalendar(com.ibm.icu.util.TimeZone zone, com.ibm.icu.util.ULocale locale)
          Constructs a Persian calendar with the specified time zone and locale.
PersianCalendar(com.ibm.icu.util.ULocale locale)
          Constructs a Persian calendar with the default time zone and the specified locale.
 
Method Summary
 void add(int field, int amount)
          Adds the specified amount to the specified field of this calendar.
 java.lang.String getType()
          Type of this calendar.
 
Methods inherited from class com.ibm.icu.util.Calendar
after, before, clear, clear, clone, equals, fieldDifference, get, getActualMaximum, getActualMinimum, getAvailableLocales, getAvailableULocales, getDateTimeFormat, getDateTimeFormat, getDayOfWeekType, getDisplayName, getDisplayName, getFieldCount, getFirstDayOfWeek, getGreatestMinimum, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getLeastMaximum, getLocale, getMaximum, getMinimalDaysInFirstWeek, getMinimum, getTime, getTimeInMillis, getTimeZone, getWeekendTransition, hashCode, isEquivalentTo, isLenient, isSet, isWeekend, isWeekend, roll, roll, set, set, set, set, setFirstDayOfWeek, setLenient, setMinimalDaysInFirstWeek, setTime, setTimeInMillis, setTimeZone, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

BH

public static final int BH
Before Hijra Era.

See Also:
Constant Field Values

AH

public static final int AH
After Hijra Era.

See Also:
Constant Field Values
Constructor Detail

PersianCalendar

public PersianCalendar()
Constructs a Persian calendar with the default time zone and locale.


PersianCalendar

public PersianCalendar(com.ibm.icu.util.TimeZone zone)
Constructs a Persian calendar with the specified time zone and the default locale.

Parameters:
zone - the desired timezone.

PersianCalendar

public PersianCalendar(java.util.Locale aLocale)
Constructs a Persian calendar with the default time zone and the specified locale.

Parameters:
aLocale - the desired locale.

PersianCalendar

public PersianCalendar(com.ibm.icu.util.ULocale locale)
Constructs a Persian calendar with the default time zone and the specified locale.

Parameters:
locale - the desired locale.

PersianCalendar

public PersianCalendar(com.ibm.icu.util.TimeZone zone,
                       java.util.Locale aLocale)
Constructs a Persian calendar with the specified time zone and locale.

Parameters:
zone - the desired timezone.
aLocale - the desired locale.

PersianCalendar

public PersianCalendar(com.ibm.icu.util.TimeZone zone,
                       com.ibm.icu.util.ULocale locale)
Constructs a Persian calendar with the specified time zone and locale.

Parameters:
zone - the desired timezone.
locale - the desired locale.

PersianCalendar

public PersianCalendar(java.util.Date date)
Constructs a Persian calendar with the default time zone and locale and sets its time to the specified date-time.

Parameters:
date - the date of this calendar object.

PersianCalendar

public PersianCalendar(int year,
                       int month,
                       int date)
Constructs a Persian calendar with the default time zone and locale and sets its time to the specified date.

Parameters:
year - the Persian year.
month - the Persian month (zero-based).
date - the Persian day of month.

PersianCalendar

public PersianCalendar(int year,
                       int month,
                       int date,
                       int hour,
                       int minute,
                       int second)
Constructs a Persian calendar with the default time zone and locale and sets its time to the specified time.

Parameters:
year - the Persian year.
month - the Persian month (zero-based).
date - the Persian day of month.
hour - the hours part of time.
minute - the minutes part of time.
second - the seconds part of time.
Method Detail

add

public void add(int field,
                int amount)
Adds the specified amount to the specified field of this calendar. This is overriden to correct the behavior at the end of the leap years.

Overrides:
add in class com.ibm.icu.util.Calendar
Parameters:
field - the field index.
amount - the amount to add.

getType

public java.lang.String getType()

Type of this calendar.

Type is used for loading resources. Since there is no calendar data for this type ("persian"), the CalendarData will use the fallback type ("gregorian"). This is fine, just the month names and era names must be changed. This is taken care of by PersianDateFormatSymbols, which uses a java resource bundle in its turn.

Overrides:
getType in class com.ibm.icu.util.Calendar
Returns:
type of this calendar ("persian").