1 /************************************************************************
2 * Copyright (c) 2004, Arabeyes, Nadim Shaikli
3 *
4 * This is a demo file to note how to call the upcoming hijri library.
5 * It is envisioned that both hijri and umm_alqura will be within the
6 * same library and will be triggered via a command-line (ie. passed-in
7 * flag or indicator).
8 *
9 * (www.arabeyes.org - under GPL license)
10 ************************************************************************/
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <time.h> /* for time_t */
15 #include "hijri.h"
16
17 /* Various interesting/relevant sites
18
19 old.code -> http://emr.cs.uiuc.edu/~reingold/calendar.C
20 http://www.rabiah.com/convert/convert.php3
21 http://bennyhills.fortunecity.com/elfman/454/calindex.html#TOP
22 http://www.ori.unizh.ch/hegira.html
23 http://prayer.al-islam.com/convert.asp?l=eng
24
25 http://fisher.osu.edu/~muhanna_1/Muhanna.html
26 http://www.math.nus.edu.sg/aslaksen/calendar/links.shtml#Islamic
27 http://www.phys.uu.nl/~vgent/islam/mecca/ummalqura.htm
28 */
29
30 /*
31 Sample demo file - show basics (very preliminary calls)
32 */
main(void)33 int main(void)
34 {
35 /* hijri code specifics */
36 int day, month, year;
37 sDate mydate;
38 sDate mydate2;
39 int i;
40 int error_code = 0;
41
42 time_t mytime;
43 struct tm *t_ptr;
44
45 /* Get current dte structure */
46 time(&mytime);
47
48 t_ptr = localtime(&mytime);
49
50 /* Set current time values */
51 day = t_ptr->tm_mday;
52 month = t_ptr->tm_mon + 1;
53 year = t_ptr->tm_year + 1900;
54
55 /* Convert using hijri code from meladi to hijri */
56 error_code = h_date(&mydate, day, month, year);
57
58 if (error_code)
59 printf("Got an error from the library (code = %d)", error_code);
60
61 printf("Current date (dd/mm/yyyy):\n");
62 printf("+ Gregorian Input - %2d/%2d/%4d\n", day, month, year);
63 printf(" - %s(%s) - %s(%s) %2d, %4d\n", mydate.frm_dname,
64 mydate.frm_dname_sh, mydate.frm_mname, mydate.frm_mname_sh,
65 day, year);
66 printf("+ Hijri/Islamic - %2d/%2d/%4d\n", mydate.day,
67 mydate.month, mydate.year);
68 printf(" - %s(%s) - %s(%s) %2d, %4d A.H\n",
69 mydate.to_dname, mydate.to_dname_sh,mydate.to_mname,
70 mydate.to_mname_sh, mydate.day, mydate.year);
71
72 for (i = 0; mydate.event[i] != NULL; i++)
73 {
74 printf(" Day's Event - %s\n", mydate.event[i]);
75 }
76 free(mydate.event);
77
78 error_code = g_date(&mydate2, mydate.day, mydate.month, mydate.year);
79
80 if (error_code)
81 printf("Got an error from the library (code = %d)", error_code);
82
83
84 printf("+ Gregorian Conv. - %2d/%2d/%4d\n", mydate2.day,
85 mydate2.month, mydate2.year);
86 printf(" - %s(%s) - %s(%s) %2d, %4d A.H\n",
87 mydate2.to_dname, mydate2.to_dname_sh,mydate2.to_mname,
88 mydate2.to_mname_sh, mydate2.day, mydate2.year);
89
90 printf("\n");
91
92 /* Tests for umm_alqura code */
93 printf("Umm-AlQura results:\n");
94
95 G2H(&mydate, day, month, year);
96 printf("G2H (to Hijri) - %d/%d/%d\n", mydate.day,
97 mydate.month, mydate.year);
98 printf(" - day of week is %d\n", mydate.weekday);
99
100 H2G(&mydate2, mydate.day, mydate.month, mydate.year);
101 printf("H2G (to Gregorian) - %d/%d/%d\n", mydate2.day,
102 mydate2.month, mydate2.year);
103 printf(" - day of week is %d\n", mydate2.weekday);
104
105 return(0);
106 }
107