質問編集履歴
3
誤記
test
CHANGED
File without changes
|
test
CHANGED
@@ -27,110 +27,6 @@
|
|
27
27
|
class holiday
|
28
28
|
|
29
29
|
{
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
public function get_public_holiday($from_date, $to_date){
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
// APIキー
|
38
|
-
|
39
|
-
$api_key = 'AIzaSyBkaqOMNOIL5ki_ABoQv77_3EprfaM2aOo';
|
40
|
-
|
41
|
-
// カレンダーID(Googleが提供する日本の祝日カレンダー)
|
42
|
-
|
43
|
-
$calendar_id = urlencode('japanese__ja@holiday.calendar.google.com');
|
44
|
-
|
45
|
-
// 開始日
|
46
|
-
|
47
|
-
$start = date($from_date . '\T00:00:00\Z');
|
48
|
-
|
49
|
-
// 終了日
|
50
|
-
|
51
|
-
$end = date($to_date . '\T00:00:00\Z');
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
// Google Calendar API
|
56
|
-
|
57
|
-
$url = "https://www.googleapis.com/calendar/v3/calendars/" . $calendar_id . "/events?";
|
58
|
-
|
59
|
-
$query = [
|
60
|
-
|
61
|
-
'key' => $api_key,
|
62
|
-
|
63
|
-
'timeMin' => $start,
|
64
|
-
|
65
|
-
'timeMax' => $end,
|
66
|
-
|
67
|
-
'maxResults' => 50,
|
68
|
-
|
69
|
-
'orderBy' => 'startTime',
|
70
|
-
|
71
|
-
'singleEvents' => 'true'
|
72
|
-
|
73
|
-
];
|
74
|
-
|
75
|
-
$results = [];
|
76
|
-
|
77
|
-
if ($data = file_get_contents($url. http_build_query($query), true)) {
|
78
|
-
|
79
|
-
$data = json_decode($data);
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
// $data->itemには日本の祝日カレンダーの"予定"が入る
|
84
|
-
|
85
|
-
foreach ($data->items as $row) {
|
86
|
-
|
87
|
-
// [祝日の日付 => 祝日のタイトル]
|
88
|
-
|
89
|
-
$results[$row->start->date] = $row->summary;
|
90
|
-
|
91
|
-
}
|
92
|
-
|
93
|
-
}
|
94
|
-
|
95
|
-
return $results;
|
96
|
-
|
97
|
-
}
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
public function get_weekend($from_date, $to_date){
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
$holiday = array();
|
108
|
-
|
109
|
-
do{
|
110
|
-
|
111
|
-
$datetime = new DateTime($from_date);
|
112
|
-
|
113
|
-
if ((int)$datetime->format('w') == 0 || (int)$datetime->format('w') == 6){
|
114
|
-
|
115
|
-
array_push($holiday, $from_date);
|
116
|
-
|
117
|
-
}
|
118
|
-
|
119
|
-
$from_date = date("Y-m-d", strtotime($from_date . "+1 day"));
|
120
|
-
|
121
|
-
echo $from_date;
|
122
|
-
|
123
|
-
}while ($from_date <= $to_date);
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
return $holiday;
|
128
|
-
|
129
|
-
}
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
30
|
|
135
31
|
public function get_weekdays($from_date, $to_date)
|
136
32
|
|
@@ -174,176 +70,4 @@
|
|
174
70
|
|
175
71
|
|
176
72
|
|
177
|
-
|
178
|
-
|
179
73
|
```
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
### ソースコード(クラスにしない場合うまくいく)
|
190
|
-
|
191
|
-
```php
|
192
|
-
|
193
|
-
$from_date = "2020-08-07";
|
194
|
-
|
195
|
-
$to_date = "2020-08-18";
|
196
|
-
|
197
|
-
$from_date2 = "2020-08-07";
|
198
|
-
|
199
|
-
$to_date2 = "2020-08-18";
|
200
|
-
|
201
|
-
$from_date3 = "2020-08-07";
|
202
|
-
|
203
|
-
$to_date3 = "2020-08-18";
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
$days = array();
|
210
|
-
|
211
|
-
do{
|
212
|
-
|
213
|
-
array_push($days, $from_date);
|
214
|
-
|
215
|
-
$from_date = date("Y-m-d", strtotime($from_date . "+1 day"));
|
216
|
-
|
217
|
-
}while ($from_date <= $to_date);
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
$weekend = get_weekend($from_date2, $to_date2);
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
$aa = array_values(array_diff($days, $weekend));
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
$bb = array_flip(get_public_holiday($from_date3, $to_date3));
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
$aa = array_values(array_diff($aa, $bb));
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
var_dump($aa);
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
function get_weekend($from_date, $to_date){
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
$holiday = array();
|
250
|
-
|
251
|
-
do{
|
252
|
-
|
253
|
-
$datetime = new DateTime($from_date);
|
254
|
-
|
255
|
-
if ((int)$datetime->format('w') == 0 || (int)$datetime->format('w') == 6){
|
256
|
-
|
257
|
-
array_push($holiday, $from_date);
|
258
|
-
|
259
|
-
}
|
260
|
-
|
261
|
-
if ($from_date < $to_date) {
|
262
|
-
|
263
|
-
$from_date = date("Y-m-d", strtotime($from_date . "+1 day"));
|
264
|
-
|
265
|
-
}
|
266
|
-
|
267
|
-
}while ($from_date != $to_date);
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
return $holiday;
|
272
|
-
|
273
|
-
}
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
function get_public_holiday($from_date, $to_date){
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
// APIキー
|
282
|
-
|
283
|
-
$api_key = 'AIzaSyBkaqOMNOIL5ki_ABoQv77_3EprfaM2aOo';
|
284
|
-
|
285
|
-
// カレンダーID(Googleが提供する日本の祝日カレンダー)
|
286
|
-
|
287
|
-
$calendar_id = urlencode('japanese__ja@holiday.calendar.google.com');
|
288
|
-
|
289
|
-
// 開始日
|
290
|
-
|
291
|
-
$start = date($from_date . '\T00:00:00\Z');
|
292
|
-
|
293
|
-
// 終了日
|
294
|
-
|
295
|
-
$end = date($to_date . '\T00:00:00\Z');
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
// Google Calendar API
|
300
|
-
|
301
|
-
$url = "https://www.googleapis.com/calendar/v3/calendars/" . $calendar_id . "/events?";
|
302
|
-
|
303
|
-
$query = [
|
304
|
-
|
305
|
-
'key' => $api_key,
|
306
|
-
|
307
|
-
'timeMin' => $start,
|
308
|
-
|
309
|
-
'timeMax' => $end,
|
310
|
-
|
311
|
-
'maxResults' => 50,
|
312
|
-
|
313
|
-
'orderBy' => 'startTime',
|
314
|
-
|
315
|
-
'singleEvents' => 'true'
|
316
|
-
|
317
|
-
];
|
318
|
-
|
319
|
-
$results = [];
|
320
|
-
|
321
|
-
if ($data = file_get_contents($url. http_build_query($query), true)) {
|
322
|
-
|
323
|
-
$data = json_decode($data);
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
// $data->itemには日本の祝日カレンダーの"予定"が入る
|
328
|
-
|
329
|
-
foreach ($data->items as $row) {
|
330
|
-
|
331
|
-
// [祝日の日付 => 祝日のタイトル]
|
332
|
-
|
333
|
-
$results[$row->start->date] = $row->summary;
|
334
|
-
|
335
|
-
}
|
336
|
-
|
337
|
-
}
|
338
|
-
|
339
|
-
return $results;
|
340
|
-
|
341
|
-
}
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
```
|
2
誤記
test
CHANGED
File without changes
|
test
CHANGED
@@ -212,138 +212,134 @@
|
|
212
212
|
|
213
213
|
array_push($days, $from_date);
|
214
214
|
|
215
|
+
$from_date = date("Y-m-d", strtotime($from_date . "+1 day"));
|
216
|
+
|
217
|
+
}while ($from_date <= $to_date);
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
$weekend = get_weekend($from_date2, $to_date2);
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
$aa = array_values(array_diff($days, $weekend));
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
$bb = array_flip(get_public_holiday($from_date3, $to_date3));
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
$aa = array_values(array_diff($aa, $bb));
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
var_dump($aa);
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
function get_weekend($from_date, $to_date){
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
$holiday = array();
|
250
|
+
|
251
|
+
do{
|
252
|
+
|
253
|
+
$datetime = new DateTime($from_date);
|
254
|
+
|
255
|
+
if ((int)$datetime->format('w') == 0 || (int)$datetime->format('w') == 6){
|
256
|
+
|
257
|
+
array_push($holiday, $from_date);
|
258
|
+
|
259
|
+
}
|
260
|
+
|
215
|
-
if ($from_date < $to_date) {
|
261
|
+
if ($from_date < $to_date) {
|
216
|
-
|
262
|
+
|
217
|
-
$from_date = date("Y-m-d", strtotime($from_date . "+1 day"));
|
263
|
+
$from_date = date("Y-m-d", strtotime($from_date . "+1 day"));
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
}while ($from_date != $to_date);
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
return $holiday;
|
272
|
+
|
273
|
+
}
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
function get_public_holiday($from_date, $to_date){
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
// APIキー
|
282
|
+
|
283
|
+
$api_key = 'AIzaSyBkaqOMNOIL5ki_ABoQv77_3EprfaM2aOo';
|
284
|
+
|
285
|
+
// カレンダーID(Googleが提供する日本の祝日カレンダー)
|
286
|
+
|
287
|
+
$calendar_id = urlencode('japanese__ja@holiday.calendar.google.com');
|
288
|
+
|
289
|
+
// 開始日
|
290
|
+
|
291
|
+
$start = date($from_date . '\T00:00:00\Z');
|
292
|
+
|
293
|
+
// 終了日
|
294
|
+
|
295
|
+
$end = date($to_date . '\T00:00:00\Z');
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
// Google Calendar API
|
300
|
+
|
301
|
+
$url = "https://www.googleapis.com/calendar/v3/calendars/" . $calendar_id . "/events?";
|
302
|
+
|
303
|
+
$query = [
|
304
|
+
|
305
|
+
'key' => $api_key,
|
306
|
+
|
307
|
+
'timeMin' => $start,
|
308
|
+
|
309
|
+
'timeMax' => $end,
|
310
|
+
|
311
|
+
'maxResults' => 50,
|
312
|
+
|
313
|
+
'orderBy' => 'startTime',
|
314
|
+
|
315
|
+
'singleEvents' => 'true'
|
316
|
+
|
317
|
+
];
|
318
|
+
|
319
|
+
$results = [];
|
320
|
+
|
321
|
+
if ($data = file_get_contents($url. http_build_query($query), true)) {
|
322
|
+
|
323
|
+
$data = json_decode($data);
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
// $data->itemには日本の祝日カレンダーの"予定"が入る
|
328
|
+
|
329
|
+
foreach ($data->items as $row) {
|
330
|
+
|
331
|
+
// [祝日の日付 => 祝日のタイトル]
|
332
|
+
|
333
|
+
$results[$row->start->date] = $row->summary;
|
334
|
+
|
335
|
+
}
|
336
|
+
|
337
|
+
}
|
338
|
+
|
339
|
+
return $results;
|
218
340
|
|
219
341
|
}
|
220
342
|
|
221
|
-
}while ($from_date != $to_date);
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
$weekend = get_weekend($from_date2, $to_date2);
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
$aa = array_values(array_diff($days, $weekend));
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
$bb = array_flip(get_public_holiday($from_date3, $to_date3));
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
$aa = array_values(array_diff($aa, $bb));
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
var_dump($aa);
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
function get_weekend($from_date, $to_date){
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
$holiday = array();
|
254
|
-
|
255
|
-
do{
|
256
|
-
|
257
|
-
$datetime = new DateTime($from_date);
|
258
|
-
|
259
|
-
if ((int)$datetime->format('w') == 0 || (int)$datetime->format('w') == 6){
|
260
|
-
|
261
|
-
array_push($holiday, $from_date);
|
262
|
-
|
263
|
-
}
|
264
|
-
|
265
|
-
if ($from_date < $to_date) {
|
266
|
-
|
267
|
-
$from_date = date("Y-m-d", strtotime($from_date . "+1 day"));
|
268
|
-
|
269
|
-
}
|
270
|
-
|
271
|
-
}while ($from_date != $to_date);
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
return $holiday;
|
276
|
-
|
277
|
-
}
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
function get_public_holiday($from_date, $to_date){
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
// APIキー
|
286
|
-
|
287
|
-
$api_key = 'AIzaSyBkaqOMNOIL5ki_ABoQv77_3EprfaM2aOo';
|
288
|
-
|
289
|
-
// カレンダーID(Googleが提供する日本の祝日カレンダー)
|
290
|
-
|
291
|
-
$calendar_id = urlencode('japanese__ja@holiday.calendar.google.com');
|
292
|
-
|
293
|
-
// 開始日
|
294
|
-
|
295
|
-
$start = date($from_date . '\T00:00:00\Z');
|
296
|
-
|
297
|
-
// 終了日
|
298
|
-
|
299
|
-
$end = date($to_date . '\T00:00:00\Z');
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
// Google Calendar API
|
304
|
-
|
305
|
-
$url = "https://www.googleapis.com/calendar/v3/calendars/" . $calendar_id . "/events?";
|
306
|
-
|
307
|
-
$query = [
|
308
|
-
|
309
|
-
'key' => $api_key,
|
310
|
-
|
311
|
-
'timeMin' => $start,
|
312
|
-
|
313
|
-
'timeMax' => $end,
|
314
|
-
|
315
|
-
'maxResults' => 50,
|
316
|
-
|
317
|
-
'orderBy' => 'startTime',
|
318
|
-
|
319
|
-
'singleEvents' => 'true'
|
320
|
-
|
321
|
-
];
|
322
|
-
|
323
|
-
$results = [];
|
324
|
-
|
325
|
-
if ($data = file_get_contents($url. http_build_query($query), true)) {
|
326
|
-
|
327
|
-
$data = json_decode($data);
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
// $data->itemには日本の祝日カレンダーの"予定"が入る
|
332
|
-
|
333
|
-
foreach ($data->items as $row) {
|
334
|
-
|
335
|
-
// [祝日の日付 => 祝日のタイトル]
|
336
|
-
|
337
|
-
$results[$row->start->date] = $row->summary;
|
338
|
-
|
339
|
-
}
|
340
|
-
|
341
|
-
}
|
342
|
-
|
343
|
-
return $results;
|
344
|
-
|
345
|
-
}
|
346
|
-
|
347
343
|
|
348
344
|
|
349
345
|
|
1
誤記
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
### ソースコード
|
11
|
+
### ソースコード(期待する結果とならない)
|
12
12
|
|
13
13
|
```php
|
14
14
|
|
@@ -177,3 +177,177 @@
|
|
177
177
|
|
178
178
|
|
179
179
|
```
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
### ソースコード(クラスにしない場合うまくいく)
|
190
|
+
|
191
|
+
```php
|
192
|
+
|
193
|
+
$from_date = "2020-08-07";
|
194
|
+
|
195
|
+
$to_date = "2020-08-18";
|
196
|
+
|
197
|
+
$from_date2 = "2020-08-07";
|
198
|
+
|
199
|
+
$to_date2 = "2020-08-18";
|
200
|
+
|
201
|
+
$from_date3 = "2020-08-07";
|
202
|
+
|
203
|
+
$to_date3 = "2020-08-18";
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
$days = array();
|
210
|
+
|
211
|
+
do{
|
212
|
+
|
213
|
+
array_push($days, $from_date);
|
214
|
+
|
215
|
+
if ($from_date < $to_date) {
|
216
|
+
|
217
|
+
$from_date = date("Y-m-d", strtotime($from_date . "+1 day"));
|
218
|
+
|
219
|
+
}
|
220
|
+
|
221
|
+
}while ($from_date != $to_date);
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
$weekend = get_weekend($from_date2, $to_date2);
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
$aa = array_values(array_diff($days, $weekend));
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
$bb = array_flip(get_public_holiday($from_date3, $to_date3));
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
$aa = array_values(array_diff($aa, $bb));
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
var_dump($aa);
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
function get_weekend($from_date, $to_date){
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
$holiday = array();
|
254
|
+
|
255
|
+
do{
|
256
|
+
|
257
|
+
$datetime = new DateTime($from_date);
|
258
|
+
|
259
|
+
if ((int)$datetime->format('w') == 0 || (int)$datetime->format('w') == 6){
|
260
|
+
|
261
|
+
array_push($holiday, $from_date);
|
262
|
+
|
263
|
+
}
|
264
|
+
|
265
|
+
if ($from_date < $to_date) {
|
266
|
+
|
267
|
+
$from_date = date("Y-m-d", strtotime($from_date . "+1 day"));
|
268
|
+
|
269
|
+
}
|
270
|
+
|
271
|
+
}while ($from_date != $to_date);
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
return $holiday;
|
276
|
+
|
277
|
+
}
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
function get_public_holiday($from_date, $to_date){
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
// APIキー
|
286
|
+
|
287
|
+
$api_key = 'AIzaSyBkaqOMNOIL5ki_ABoQv77_3EprfaM2aOo';
|
288
|
+
|
289
|
+
// カレンダーID(Googleが提供する日本の祝日カレンダー)
|
290
|
+
|
291
|
+
$calendar_id = urlencode('japanese__ja@holiday.calendar.google.com');
|
292
|
+
|
293
|
+
// 開始日
|
294
|
+
|
295
|
+
$start = date($from_date . '\T00:00:00\Z');
|
296
|
+
|
297
|
+
// 終了日
|
298
|
+
|
299
|
+
$end = date($to_date . '\T00:00:00\Z');
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
// Google Calendar API
|
304
|
+
|
305
|
+
$url = "https://www.googleapis.com/calendar/v3/calendars/" . $calendar_id . "/events?";
|
306
|
+
|
307
|
+
$query = [
|
308
|
+
|
309
|
+
'key' => $api_key,
|
310
|
+
|
311
|
+
'timeMin' => $start,
|
312
|
+
|
313
|
+
'timeMax' => $end,
|
314
|
+
|
315
|
+
'maxResults' => 50,
|
316
|
+
|
317
|
+
'orderBy' => 'startTime',
|
318
|
+
|
319
|
+
'singleEvents' => 'true'
|
320
|
+
|
321
|
+
];
|
322
|
+
|
323
|
+
$results = [];
|
324
|
+
|
325
|
+
if ($data = file_get_contents($url. http_build_query($query), true)) {
|
326
|
+
|
327
|
+
$data = json_decode($data);
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
// $data->itemには日本の祝日カレンダーの"予定"が入る
|
332
|
+
|
333
|
+
foreach ($data->items as $row) {
|
334
|
+
|
335
|
+
// [祝日の日付 => 祝日のタイトル]
|
336
|
+
|
337
|
+
$results[$row->start->date] = $row->summary;
|
338
|
+
|
339
|
+
}
|
340
|
+
|
341
|
+
}
|
342
|
+
|
343
|
+
return $results;
|
344
|
+
|
345
|
+
}
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
```
|