Bug fix (#6333)
[openemr.git] / library / date_functions.php
blob7b7ce61cb26a949746f9f1931d5a1a4401e7127f
1 <?php
3 // ============================================================
4 // dateformat
5 //
6 // return a formated string for date
7 // @args: string (date string), boolean (include day of week)
8 // (it uses $_SESSION['language_choice'] )
9 // @return: $date_string (string) - formated string
10 // Cristian Navalici lemonsoftware at gmail dot com
12 // For Hebrew must be implemented a special calendar functions
14 // 10.07.2007 - dateformat accepts now an argument
15 // ============================================================
17 function dateformat($strtime = '', $with_dow = false)
20 // without an argument, display current date
21 if (!$strtime) {
22 $strtime = strtotime('now');
25 // string date is formed by
26 // $dow + date(day) + $nom + date(year) or similar
28 // name the day of the week for different languages
29 $day = date("w", $strtime); // 0 sunday -> 6 saturday
31 switch ($day) {
32 case 0:
33 $dow = xl('Sunday');
34 break;
35 case 1:
36 $dow = xl('Monday');
37 break;
38 case 2:
39 $dow = xl('Tuesday');
40 break;
41 case 3:
42 $dow = xl('Wednesday');
43 break;
44 case 4:
45 $dow = xl('Thursday');
46 break;
47 case 5:
48 $dow = xl('Friday');
49 break;
50 case 6:
51 $dow = xl('Saturday');
52 break;
55 // name of the month in different languages
56 $month = (int) date('m', $strtime);
58 switch ($month) {
59 case 1:
60 $nom = xl('January');
61 break;
62 case 2:
63 $nom = xl('February');
64 break;
65 case 3:
66 $nom = xl('March');
67 break;
68 case 4:
69 $nom = xl('April');
70 break;
71 case 5:
72 $nom = xl('May');
73 break;
74 case 6:
75 $nom = xl('June');
76 break;
77 case 7:
78 $nom = xl('July');
79 break;
80 case 8:
81 $nom = xl('August');
82 break;
83 case 9:
84 $nom = xl('September');
85 break;
86 case 10:
87 $nom = xl('October');
88 break;
89 case 11:
90 $nom = xl('November');
91 break;
92 case 12:
93 $nom = xl('December');
94 break;
97 // Date string format
98 // First, get current language title
99 $languageTitle = getLanguageTitle($_SESSION['language_choice']);
100 switch ($languageTitle) {
101 // standard english first
102 case getLanguageTitle(1):
103 $dt = date("F j, Y", $strtime);
104 if ($with_dow) {
105 $dt = "$dow, $dt";
107 break;
108 case "Swedish":
109 $dt = date("Y", $strtime) . " $nom " . date("d", $strtime);
110 if ($with_dow) {
111 $dt = "$dow $dt";
113 break;
114 case "Spanish":
115 case "Spanish (Spain)":
116 case "Spanish (Latin American)":
117 $dt = date("d", $strtime) . " $nom " . date("Y", $strtime);
118 if ($with_dow) {
119 $dt = "$dow $dt";
121 break;
122 case "German":
123 $dt = date("d", $strtime) . " $nom " . date("Y", $strtime);
124 if ($with_dow) {
125 $dt = "$dow $dt";
127 break;
128 case "Dutch":
129 $dt = date("d", $strtime) . " $nom " . date("Y", $strtime);
130 if ($with_dow) {
131 $dt = "$dow $dt";
133 break;
134 // hebrew (israel) , display english NOT jewish calendar
135 case "Hebrew":
136 $dt = date("d", $strtime) . " $nom " . date("Y", $strtime);
137 if ($with_dow) {
138 $dt = "$dow, $dt";
140 break;
141 // default case
142 default:
143 $dt = "$nom " . date("d", $strtime) . ", " . date("Y", $strtime);
144 if ($with_dow) {
145 $dt = "$dow, $dt";
149 return $dt;