1: <?php
2:
3: namespace Budabot\User\Modules;
4:
5: use stdClass;
6: use DateTime;
7:
8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21:
22: class TimeController {
23:
24: 25: 26: 27:
28: public $moduleName;
29:
30:
31: public $util;
32:
33:
34: public $text;
35:
36: 37: 38: 39:
40: public function timeListCommand($message, $channel, $sender, $sendto, $args) {
41: $link .= "<header2>Australia<end>\n";
42: $link .= "<tab><highlight>Western Australia</end>\n";
43: $link .= "<tab><tab>Standard Time (AWST = GMT +8:00): " . $this->getTimezone("AWST")->time . "\n";
44: $link .= "<tab><highlight>Northern Territory/South Australia<end>\n";
45: $link .= "<tab><tab>Standard Time (ACST = GMT+9:30): " . $this->getTimezone("ACST")->time . "\n";
46: $link .= "<tab><tab>Summer Time (ACDT = GMT+10:30): " . $this->getTimezone("ACDT")->time . "\n";
47: $link .= "<tab><highlight>Queensland/Victoria/Tasmania<end>\n";
48: $link .= "<tab><tab>Standard Time (AEST = GMT+10): " . $this->getTimezone("AEST")->time . "\n";
49: $link .= "<tab><tab>Summer Time (AEDT = GMT+11): " . $this->getTimezone("AEDT")->time . "\n\n";
50:
51: $link .= "<header2>Asia<end>\n";
52: $link .= "<tab><highlight>Thailand/Vietnam/Kambodscha (ICT = GMT+7)<end>: " . $this->getTimezone("ICT")->time . "\n";
53: $link .= "<tab><highlight>China/Malaysia/Singapur/Indonesien (CST = GMT+8)<end>: " . $this->getTimezone("CCST")->time . "\n";
54: $link .= "<tab><highlight>Japan/Korea (JST = GMT+9)<end>: " . $this->getTimezone("JST")->time . "\n\n";
55:
56: $link .= "<header2>Europe<end>\n";
57: $link .= "<tab><highlight>England (GMT)<end>: " . $this->getTimezone("GMT")->time . "\n";
58: $link .= "<tab><highlight>Germany/France/Netherlands/Italy/Austria<end>\n";
59: $link .= "<tab><tab>Standard Time (CET = GMT+1): " . $this->getTimezone("CET")->time . "\n";
60: $link .= "<tab><tab>Summer Time (CEST = GMT+2): " . $this->getTimezone("CEST")->time . "\n";
61: $link .= "<tab><highlight>Ägypten/Bulgarien/Finnland/Griechenland<end>\n";
62: $link .= "<tab><tab>Standard Time (EET = GMT+2): " . $this->getTimezone("EET")->time . "\n";
63: $link .= "<tab><tab>Summer Time (EEST/EEDT = GMT+3): " . $this->getTimezone("EEST")->time . "\n";
64: $link .= "<tab><highlight>Bahrain/Irak/Russland/Saudi Arabien<end>\n";
65: $link .= "<tab><tab>Standard Time (MSK = GMT+3): " . $this->getTimezone("MSK")->time . "\n";
66: $link .= "<tab><tab>Summer Time (MSD = GMT+4): " . $this->getTimezone("MSD")->time . "\n\n";
67: $link .= "<highlight>Indien (GMT+5:30)<end>: " . $this->getTimezone("IST")->time . "\n\n";
68: $link .= "<highlight>Iran (GMT+3:30)<end>: " . $this->getTimezone("IRT")->time . "\n\n";
69:
70: $link .= "<header2>Canada<end>\n";
71: $link .= "<tab>Standard Time (NST = GMT-3:30): " . $this->getTimezone("NST")->time . "\n";
72: $link .= "<tab>Summer Time (NDT = GMT-2:30): " . $this->getTimezone("NDT")->time . "\n\n";
73:
74: $link .= "<header2>USA<end>\n";
75: $link .= "<tab><highlight>Florida/Indiana/New York/Maine/New Jersey/Washington D.C.<end>\n";
76: $link .= "<tab><tab>Standard Time (EST = GMT-5): " . $this->getTimezone("EST")->time . "\n";
77: $link .= "<tab><tab>Summer Time (EDT = GMT-4): " . $this->getTimezone("EDT")->time . "\n";
78: $link .= "<tab><highlight>Alaska<end>\n";
79: $link .= "<tab><tab>Standard Time (AKST = GMT-9): " . $this->getTimezone("AKST")->time . "\n";
80: $link .= "<tab><tab>Summer Time (AKDT = GMT-8): " . $this->getTimezone("AKDT")->time . "\n";
81: $link .= "<tab><highlight>California/Nevada/Washington<end>\n";
82: $link .= "<tab><tab>Standard Time (PST = GMT-8): " . $this->getTimezone("PST")->time . "\n";
83: $link .= "<tab><tab>Summer Time (PDT = GMT-7): " . $this->getTimezone("PDT")->time . "\n";
84: $link .= "<tab><highlight>Colorado/Montana/New Mexico/Utah<end>\n";
85: $link .= "<tab><tab>Standard Time (MST = GMT-7): " . $this->getTimezone("MST")->time . "\n";
86: $link .= "<tab><tab>Summer Time (MDT = GMT-6): " . $this->getTimezone("MDT")->time . "\n";
87: $link .= "<tab><highlight>Alabama/Illinois/Iowa/Michigan/Minnesota/Oklahoma<end>\n";
88: $link .= "<tab><tab>Standard Time (CST = GMT-6): " . $this->getTimezone("CST")->time . "\n";
89: $link .= "<tab><tab>Summer Time (CDT = GMT-5): " . $this->getTimezone("CDT")->time . "\n\n";
90:
91: $link .= "<header2>Unix time<end>\n";
92: $link .= "<tab><tab>" . time() . "\n";
93:
94: $msg = "<highlight>".$this->util->date(time())."<end>";
95: $msg .= " " . $this->text->makeBlob("All Timezones", $link);
96: $sendto->reply($msg);
97: }
98:
99: 100: 101: 102:
103: public function timeShowCommand($message, $channel, $sender, $sendto, $args) {
104: $zone = strtoupper($args[1]);
105: $timezone = $this->getTimezone($zone);
106: if ($timezone !== null) {
107: $msg = $timezone->name." is <highlight>".$timezone->time."<end>";
108: } else {
109: $msg = "Unknown timezone.";
110: }
111:
112: $sendto->reply($msg);
113: }
114:
115: public function getTimezone($tz) {
116: $date = new DateTime();
117: $time = time() - $date->getOffset();
118: $time_format = "dS M, H:i";
119:
120: switch ($tz) {
121: case "CST":
122: $name = "Central Standard Time (GMT-6)";
123: $offset = -(3600*6);
124: break;
125: case "CDT":
126: $name = "Central Daylight Time (GMT-5)";
127: $offset = -(3600*5);
128: break;
129: case "MST":
130: $name = "Mountain Standard Time (GMT-7)";
131: $offset = -(3600*7);
132: break;
133: case "MDT":
134: $name = "Mountain Daylight Time (GMT-6)";
135: $offset = -(3600*6);
136: break;
137: case "PST":
138: $name = "Pacific Standard Time (GMT-8)";
139: $offset = -(3600*8);
140: break;
141: case "PDT":
142: $name = "Pacific Daylight Time (GMT-7)";
143: $offset = -(3600*7);
144: break;
145: case "AKST":
146: $name = "Alaska Standard Time (GMT-9)";
147: $offset = -(3600*9);
148: break;
149: case "AKDT":
150: $name = "Alaska Daylight Time (GMT-8)";
151: $offset = -(3600*8);
152: break;
153: case "EST":
154: $name = "Eastern Standard Time (GMT-5)";
155: $offset = -(3600*5);
156: break;
157: case "EDT":
158: $name = "Eastern Daylight Time (GMT-4)";
159: $offset = -(3600*4);
160: break;
161: case "NST":
162: $name = "Newfoundland Standard Time (GMT-3:30)";
163: $offset = -(3600*3.5);
164: break;
165: case "NDT":
166: $name = "Newfoundland Daylight Time (GMT-2:30)";
167: $offset = -(3600*2.5);
168: break;
169: case "UTC":
170: case "GMT":
171: $name = "Greenwich Mean Time (GMT / AO)";
172: $offset = 0;
173: break;
174: case "CET":
175: $name = "Central European Time (GMT+1)";
176: $offset = 3600;
177: break;
178: case "CEST":
179: $name = "Central European Summer Time (GMT+2)";
180: $offset = 3600*2;
181: break;
182: case "EET":
183: $name = "Eastern European Time (GMT+2)";
184: $offset = 3600*2;
185: break;
186: case "EEST":
187: $name = "Eastern European Summer Time (GMT+3)";
188: $offset = 3600*3;
189: break;
190: case "EEDT":
191: $name = "Eastern European Daylight Time (GMT+3)";
192: $offset = 3600*3;
193: break;
194: case "MSK":
195: $name = "Moscow Time (GMT+3)";
196: $offset = 3600*3;
197: break;
198: case "MSD":
199: $name = "Moscow Daylight Time (GMT+4)";
200: $offset = 3600*4;
201: break;
202: case "IRT":
203: $name = "Iran Time (GMT+3:30)";
204: $offset = 3600*3.5;
205: break;
206: case "IST":
207: $name = "Indian Standard Time (GMT+5:30)";
208: $offset = 3600*5.5;
209: break;
210: case "ICT":
211: $name = "Indochina Time (GMT+7)";
212: $offset = 3600*7;
213: break;
214: case "CCST":
215: $name = "China Standard Time (GMT+8)";
216: $offset = 3600*8;
217: break;
218: case "JST":
219: $name = "Japan Standard Time (GMT+9)";
220: $offset = 3600*9;
221: break;
222: case "AWST":
223: $name = "Australian Western Standard Time (GMT+8)";
224: $offset = 3600*8;
225: break;
226: case "ACST":
227: $name = "Australian Central Standard Time (GMT+9:30)";
228: $offset = 3600*9.5;
229: break;
230: case "ACDT":
231: $name = "Australian Central Daylight Time (GMT+10:30)";
232: $offset = 3600*10.5;
233: break;
234: case "AEST":
235: $name = "Australian Eastern Standard Time (GMT+10)";
236: $offset = 3600*10;
237: break;
238: case "AEDT":
239: $name = "Australian Eastern Daylight Time (GMT+11)";
240: $offset = 3600*11;
241: break;
242: default:
243: return null;
244: }
245:
246: $obj = new stdClass;
247: $obj->name = $name;
248: $obj->offset = $offset;
249: $obj->time = date($time_format, $time + $offset);
250: return $obj;
251: }
252: }
253: