Persian Date 1.0.1
http://www.dihav.com/
By Mohammad Yousefi
vahid_you2004@yahoo.com
April 2013
Contents
- This program is freeware and can be distributed by everyone.
- No person or company may charge a fee for the distribution of this product.
- No warranty of any kind is expressed or implied. You use at your own risk. The author will not be liable for data loss, damages, loss of profits or any other kind of loss while using or misusing this program.
- You may not rent, lease, and sell this program. Any such unauthorized use shall result in immediate and automatic termination of this license and may result in criminal and/or civil prosecution.
Using this program signifies acceptance of these terms and conditions of the license.
Top
This program is some functions exactly like delphi date functions for the persian calendar.
You can use delphi help by removing the "Persian" and "Gregorian" words from the function name.
This program built by "Delphi 7" and also tested in "Delphi XE2".
Top
- Run Delphi.
- Select "Environment Options..." from "Tools" menu.
- Go to "Library" tab.
- Click the "..." button beside "Library Path" text box.
- Browse for the "PersianDate.pas" directory.
- Click "Add" button.
- Click "OK" button.
- Click "OK" button.
- To use unit functions add "PersianDate" to uses.
Top
- TDateOrder=(doYMD,doYDM,doMDY,doMYD,doDMY,doDYM);
The format of the date string.
Top
- PersianAndGregorianTimeStampDateDifference=226895;
The number of days between gregorian 0001/01/01 and persian 0001/01/01.
- PersianDateDelta=DateDelta-PersianAndGregorianTimeStampDateDifference;
Specifies the difference between TDateTime and persian TTimeStamp values.(466699 days)
- PersianFormatSettings:TFormatSettings=(
CurrencyFormat:2;
NegCurrFormat:3;
ThousandSeparator:',';
DecimalSeparator:'/';
CurrencyDecimals:2;
DateSeparator:'/';
TimeSeparator:':';
ListSeparator:'؛';
CurrencyString:'ريال';
ShortDateFormat:'yyyy/MM/dd';
LongDateFormat:'yyyy/MM/dd';
TimeAMString:'ق.ظ';
TimePMString:'ب.ظ';
ShortTimeFormat:'hh:mm AMPM';
LongTimeFormat:'hh:mm:ss AMPM';
ShortMonthNames:('اسف','بهم','دي','آذر','آبا','مهر','شهر','مرد','تير','خرد','ارد','فرو');
LongMonthNames:('اسفند','بهمن','دي','آذر','آبان','مهر','شهريور','مرداد','تير','خرداد','ارديبهشت','فروردين');
ShortDayNames:('ج','پ','چ','س','د','ي','ش');
LongDayNames:('جمعه','پنج شنبه','چهار شنبه','سه شنبه','دو شنبه','يك شنبه','شنبه');
TwoDigitYearCenturyWindow:2;
);
Persian string conversion format settings.
- EnglishFormatSettings:TFormatSettings=(
CurrencyFormat:2;
NegCurrFormat:3;
ThousandSeparator:',';
DecimalSeparator:'/';
CurrencyDecimals:2;
DateSeparator:'/';
TimeSeparator:':';
ListSeparator:';';
CurrencyString:'$';
ShortDateFormat:'yyyy/MM/dd';
LongDateFormat:'yyyy/MM/dd';
TimeAMString:'AM';
TimePMString:'PM';
ShortTimeFormat:'hh:mm AMPM';
LongTimeFormat:'hh:mm:ss AMPM';
ShortMonthNames:('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
LongMonthNames:('January','February','March','April','May','June','July','August','September','October','November','December');
ShortDayNames:('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
LongDayNames:('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
TwoDigitYearCenturyWindow:2;
);
English string conversion format settings.
- PersianDaySaturday=1;
- PersianDaySunday=2;
- PersianDayMonday=3;
- PersianDayTuesday=4;
- PersianDayWednesday=5;
- PersianDayThursday=6;
- PersianDayFriday=7;
- PersianMonthDays:array [Boolean] of TDayTable=(
(31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29),
(31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 30)
);
Top
- function PersianSystemTimeToTimeStamp(PersianSystemTime:TSystemTime):TTimeStamp;
- function PersianTimeStampToSystemTime(PersianTimeStamp:TTimeStamp):TSystemTime;
- function PersianTimeStampToDateTime(PersianTimeStamp:TTimeStamp):TDateTime;
- function DateTimeToPersianTimeStamp(DateTime:TDateTime):TTimeStamp;
- function PersianSystemTimeToDateTime(PersianSystemTime:TSystemTime):TDateTime;
- function DateTimeToPersianSystemTime(DateTime:TDateTime):TSystemTime;
The functions are the same as delphi date functions.
Note that in TSystemTime "wDayOfWeek" specifies the day of the week starting from zero; Saturday = 0, Sunday = 1, and so on.
Top
- function GregorianTimeStampToPersianTimeStamp(GregorianTimeStamp:TTimeStamp):TTimeStamp;
- function PersianTimeStampToGregorianTimeStamp(PersianTimeStamp:TTimeStamp):TTimeStamp;
- function GregorianSystemTimeToPersianSystemTime(GregorianSystemTime:TSystemTime):TSystemTime;
- function PersianSystemTimeToGregorianSystemTime(PersianSystemTime:TSystemTime):TSystemTime;
- function GregorianDateTimeToPersianTimeStamp(GregorianDateTime:TDateTime):TTimeStamp;
- function PersianTimeStampToGregorianDateTime(PersianTimeStamp:TTimeStamp):TDateTime;
- function GregorianDateTimeToPersianSystemTime(GregorianDateTime:TDateTime):TSystemTime;
- function PersianSystemTimeToGregorianDateTime(PersianSystemTime:TSystemTime):TDateTime;
The functions are the same as delphi date functions.
Note that in TSystemTime "wDayOfWeek" specifies the day of the week starting from zero; Saturday = 0, Sunday = 1, and so on.
Top
- function MakeSystemTime(wYear,wMonth,wDay,wDayOfWeek,wHour,wMinute,wSecond,wMilliseconds:Word):TSystemTime;
- function EncodePersianDate(Year,Month,Day:Word):TDateTime;
- function TryEncodePersianDate(Year,Month,Day:Word;out Date:TDateTime):Boolean;
- procedure DecodePersianDate(const DateTime:TDateTime;var Year,Month,Day:Word);
- function DecodePersianDateFully(const DateTime:TDateTime;var Year,Month,Day,DOW:Word):Boolean;
The functions are the same as delphi date functions.
Note that in TSystemTime "wDayOfWeek" specifies the day of the week starting from zero; Saturday = 0, Sunday = 1, and so on.
Note that in "DecodePersianDateFully" function "DOW" specifies the day of the week starting from one; Saturday = 1, Sunday = 2, and so on.
Top
- function IsPersianLeapYear(Year:Integer):Boolean;
- function ThePersianYear(aDate:TDateTime):Word;
- function ThePersianMonth(aDate:TDateTime):Word;
- function ThePersianMonthLongName(aDate:TDateTime;const FormatSettings:TFormatSettings):String; overload;
- function ThePersianMonthLongName(aDate:TDateTime):String; overload;
- function ThePersianMonthShortName(aDate:TDateTime;const FormatSettings:TFormatSettings):String; overload;
- function ThePersianMonthShortName(aDate:TDateTime):String; overload;
- function PersianDayOfTheMonth(aDate:TDateTime):Word;
- function PersianDayOfTheYear(aDate:TDateTime):Word;
- function PersianDayOfTheWeek(aDate:TDateTime):Word;
- function PersianDayOfTheWeekLongName(aDate:TDateTime;const FormatSettings:TFormatSettings):String; overload;
- function PersianDayOfTheWeekLongName(aDate:TDateTime):String; overload;
- function PersianDayOfTheWeekShortName(aDate:TDateTime;const FormatSettings:TFormatSettings):String; overload;
- function PersianDayOfTheWeekShortName(aDate:TDateTime):String; overload;
- function CurrentPersianYear:Word;
- function CurrentPersianMonth:Word;
- function CurrentPersianMonthLongName(const FormatSettings:TFormatSettings):String; overload;
- function CurrentPersianMonthLongName:String; overload;
- function CurrentPersianMonthShortName(const FormatSettings:TFormatSettings):String; overload;
- function CurrentPersianMonthShortName:String; overload;
- function CurrentPersianDayOfMonth:Word;
- function CurrentPersianDayOfYear:Word;
- function CurrentPersianDayOfWeek:Word;
- function CurrentPersianDayOfWeekLongName(const FormatSettings:TFormatSettings):String; overload;
- function CurrentPersianDayOfWeekLongName:String; overload;
- function CurrentPersianDayOfWeekShortName(const FormatSettings:TFormatSettings):String; overload;
- function CurrentPersianDayOfWeekShortName:String; overload;
The functions are the same as delphi date functions.
Note that "DayOfWeek" specifies the day of the week starting from one; Saturday = 1, Sunday = 2, and so on.
Top
- function IncPersianDay(const DateTime:TDateTime;NumberOfDays:Integer=1):TDateTime;
- procedure IncAPersianDay(var Year,Month,Day:Word;NumberOfDays:Integer=1);
- function DecPersianDay(const DateTime:TDateTime;NumberOfDays:Integer=1):TDateTime;
- procedure DecAPersianDay(var Year,Month,Day:Word;NumberOfDays:Integer=1);
- function IncPersianWeek(const DateTime:TDateTime;NumberOfWeeks:Integer=1):TDateTime;
- procedure IncAPersianWeek(var Year,Month,Day:Word;NumberOfWeeks:Integer=1);
- function DecPersianWeek(const DateTime:TDateTime;NumberOfWeeks:Integer=1):TDateTime;
- procedure DecAPersianWeek(var Year,Month,Day:Word;NumberOfWeeks:Integer=1);
- function IncPersianMonth(const DateTime:TDateTime;NumberOfMonths:Integer=1):TDateTime;
- procedure IncAPersianMonth(var Year,Month,Day:Word;NumberOfMonths:Integer=1);
- function DecPersianMonth(const DateTime:TDateTime;NumberOfMonths:Integer=1):TDateTime;
- procedure DecAPersianMonth(var Year,Month,Day:Word;NumberOfMonths:Integer=1);
- function IncPersianYear(const DateTime:TDateTime;NumberOfYears:Integer=1):TDateTime;
- procedure IncAPersianYear(var Year,Month,Day:Word;NumberOfYears:Integer=1);
- function DecPersianYear(const DateTime:TDateTime;NumberOfYears:Integer=1):TDateTime;
- procedure DecAPersianYear(var Year,Month,Day:Word;NumberOfYears:Integer=1);
The functions are the same as delphi date functions.
Top
- procedure PersianSystemTimeToString(var Result:string;const Format:String;PersianSystemTime:TSystemTime;const FormatSettings:TFormatSettings); overload;
- procedure PersianSystemTimeToString(var Result:string;const Format:String;PersianSystemTime:TSystemTime); overload;
- procedure PersianTimeStampToString(var Result:string;const Format:String;PersianTimeStamp:TTimeStamp;const FormatSettings:TFormatSettings); overload;
- procedure PersianTimeStampToString(var Result:string;const Format:String;PersianTimeStamp:TTimeStamp); overload;
- procedure PersianDateTimeToString(var Result:string;const Format:String;DateTime:TDateTime;const FormatSettings:TFormatSettings); overload;
- procedure PersianDateTimeToString(var Result:string;const Format:String;DateTime:TDateTime); overload;
- function PersianDateToStr(const DateTime:TDateTime;const FormatSettings:TFormatSettings):string; overload;
- function PersianDateToStr(const DateTime:TDateTime):string; overload;
- function PersianDateTimeToStr(const DateTime:TDateTime;const FormatSettings:TFormatSettings):string; overload;
- function PersianDateTimeToStr(const DateTime:TDateTime):string; overload;
- function FormatPersianDateTime(const Format:string;DateTime:TDateTime;const FormatSettings:TFormatSettings):string; overload;
- function FormatPersianDateTime(const Format:string;DateTime:TDateTime):string; overload;
The functions are the same as delphi date functions.
For more information about Format string search "Date-Time Format Strings" in delphi help.
Top
- function StrToPersianDate(const S:string):TDateTime; overload;
- function StrToPersianDate(const S:string;const FormatSettings:TFormatSettings):TDateTime; overload;
- function StrToPersianDateDef(const S:string;const Default:TDateTime):TDateTime; overload;
- function StrToPersianDateDef(const S:string;const Default:TDateTime;const FormatSettings:TFormatSettings):TDateTime; overload;
- function TryStrToPersianDate(const S:string;out Value:TDateTime):Boolean; overload;
- function TryStrToPersianDate(const S:string;out Value:TDateTime;const FormatSettings:TFormatSettings):Boolean; overload;
- function StrToPersianDateTime(const S:string):TDateTime; overload;
- function StrToPersianDateTime(const S:string;const FormatSettings:TFormatSettings):TDateTime; overload;
- function StrToPersianDateTimeDef(const S:string;const Default:TDateTime):TDateTime; overload;
- function StrToPersianDateTimeDef(const S:string;const Default:TDateTime;const FormatSettings:TFormatSettings):TDateTime; overload;
- function TryStrToPersianDateTime(const S:string;out Value:TDateTime):Boolean; overload;
- function TryStrToPersianDateTime(const S:string;out Value:TDateTime;const FormatSettings:TFormatSettings):Boolean; overload;
- function ExtractPersianDateFromString(const S:string;DateOrder:TDateOrder;out Value:TDateTime):Boolean; overload;
- function ExtractPersianDateFromString(const S:string;DateOrder:TDateOrder;out Value:TDateTime;const FormatSettings:TFormatSettings):Boolean; overload;
The functions are the same as delphi date functions.
Use "ExtractPersianDateFromString" function to extract date from a text.
Top
- function NumberToPersianText(I:Int64):String;
- function NumberToPersianOrdinalText(I:Int64):String;
- function NumberToText(I:Int64):String;
- function NumberToOrdinalText(I:Int64):String;
- function NumberToOrdinalNumber(I:Int64):String;
You can use these functions to convert numbers to text.
Top
Visit dihav website.