1: <?php
2:
3: namespace webfilesframework\core\datatypes\time;
4: use webfilesframework\MWebfilesFrameworkException;
5:
6: 7: 8: 9: 10: 11:
12: class MTimestampHelper
13: {
14:
15: public static function getMonthStart($month = -1, $year = -1)
16: {
17: if ($month == -1) {
18: $month = date("n");
19: }
20: if ($year == -1) {
21: $year = date("Y");
22: }
23: return mktime(0, 0, 0, $month, 1, $year);
24: }
25:
26: 27: 28: 29: 30: 31:
32: public static function getMonthEnd($month = -1, $year = -1)
33: {
34: if ($month == -1) {
35: $month = date("n");
36: }
37: if ($year == -1) {
38: $year = date("Y");
39: }
40:
41:
42: $tempTime = mktime(0, 0, 0, $month, 1, $year);
43: $tempTime = date("t", $tempTime);
44:
45: return mktime(23, 59, 59, $month, $tempTime, $year);
46: }
47:
48:
49: 50: 51: 52: 53:
54: public static function getHours($duration)
55: {
56: $duration = $duration % (24 * 3600);
57: return floor($duration / 3600);
58: }
59:
60:
61: 62: 63: 64: 65:
66: public static function getMinutes($duration)
67: {
68: $duration = $duration % 3600;
69: return floor($duration / 60);
70: }
71:
72: 73: 74: 75: 76: 77:
78: public static function getDay($timestamp, $leadingZero = true)
79: {
80: if ($leadingZero) {
81: return date("d", $timestamp);
82: } else {
83: return date("j", $timestamp);
84: }
85: }
86:
87:
88: 89: 90: 91: 92: 93:
94: public static function getMonth($timestamp, $leadingZero = true)
95: {
96: if ($leadingZero) {
97: return date("m", $timestamp);
98: } else {
99: return date("n", $timestamp);
100: }
101: }
102:
103: 104: 105: 106: 107:
108: public static function getYear($timestamp)
109: {
110: return date("Y", $timestamp);
111: }
112:
113:
114: 115: 116: 117: 118:
119: public static function getHour($timestamp)
120: {
121: return date("H", $timestamp);
122: }
123:
124:
125: 126: 127: 128: 129:
130: public static function getMinute($timestamp)
131: {
132: return date("i", $timestamp);
133: }
134:
135: 136: 137: 138: 139:
140: public static function getFormatedDate($timestamp)
141: {
142: return MTimestampHelper::getDay($timestamp) . "." . MTimestampHelper::getMonth($timestamp) . "." . MTimestampHelper::getYear($timestamp);
143: }
144:
145:
146: 147: 148: 149: 150:
151: public static function getFormatedTime($timestamp)
152: {
153: return MTimestampHelper::getHour($timestamp) . ":" . MTimestampHelper::getMinute($timestamp);
154: }
155:
156: 157: 158: 159: 160:
161: public static function getWeekdayName($identifier)
162: {
163: switch ($identifier) {
164: case 0:
165: return "Sonntag";
166: break;
167:
168: case 1:
169: return "Montag";
170: break;
171:
172: case 2:
173: return "Dienstag";
174: break;
175:
176: case 3:
177: return "Mittwoch";
178: break;
179:
180: case 4:
181: return "Donnerstag";
182: break;
183:
184: case 5:
185: return "Freitag";
186: break;
187:
188: case 6:
189: return "Samstag";
190: break;
191:
192: default:
193: throw new MWebfilesFrameworkException("Unknown identifier. Identifier must be in the range of 0 and 6.");
194: break;
195: }
196: }
197:
198: public static function getDojoFormatedDate($timestamp)
199: {
200:
201: $day = MTimestampHelper::getDay(intval($timestamp));
202: $month = MTimestampHelper::getMonth(intval($timestamp));
203: $year = MTimestampHelper::getYear(intval($timestamp));
204:
205: return $year . "-" . $month . "-" . $day;
206: }
207:
208: public static function getDojoFormatedTime($timestamp)
209: {
210: $hour = MTimestampHelper::getHour(intval($timestamp));
211: $minute = MTimestampHelper::getMinute(intval($timestamp));
212:
213: return "T" . $hour . ":" . $minute . ":00";
214: }
215:
216: public static function getTimestampFromDojoFromatedDate($dojoDate)
217: {
218: $dojoDate = explode("-", $dojoDate);
219:
220: if (count($dojoDate) == 3) {
221: $day = intval($dojoDate[2]);
222: $month = intval($dojoDate[1]);
223: $year = intval($dojoDate[0]);
224:
225: $timestamp = mktime('0', '0', '0', $month, $day, $year);
226: } else {
227: $timestamp = mktime('0', '0', '0', '0', '0', '0');
228: }
229:
230:
231: return $timestamp;
232: }
233:
234: public static function getTimestampFromDojoFromatedDateTime($dojoDate, $dojoTime)
235: {
236:
237: $dojoDate = explode("-", $dojoDate);
238:
239: $day = intval($dojoDate[2]);
240: $month = intval($dojoDate[1]);
241: $year = intval($dojoDate[0]);
242:
243: $hour = substr($dojoTime, 1, 2);;
244: $minute = substr($dojoTime, 4, 2);;
245:
246: $timestamp = mktime($hour, $minute, '0', $month, $day, $year);
247:
248: return $timestamp;
249: }
250:
251: 252: 253:
254: public static function getTimestampFromExifFormatedDateTime($exifDateTime) {
255:
256: $exifDateTimeSplitted = explode(" ", $exifDateTime);
257:
258: $exifDateSplitted = explode(":",$exifDateTimeSplitted[0]);
259: $year = $exifDateSplitted[0];
260: $month = $exifDateSplitted[1];
261: $day = $exifDateSplitted[2];
262:
263: $exifTimeSplitted = explode(":",$exifDateTimeSplitted[1]);
264: $hour = $exifTimeSplitted[0];
265: $minute = $exifTimeSplitted[1];
266: $second = $exifTimeSplitted[2];
267:
268: $timestamp = mktime($hour, $minute, $second, $month, $day, $year);
269:
270: return $timestamp;
271: }
272:
273: }