Skip to content
This repository was archived by the owner on Oct 17, 2021. It is now read-only.

Commit b9733ab

Browse files
committed
test for weekly/weekday recurrences
1 parent 36ced81 commit b9733ab

File tree

3 files changed

+101
-29
lines changed

3 files changed

+101
-29
lines changed

index-json.php

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
border-radius: 3px;
5858
background: red;
5959
color: #ffffff;
60-
padding: 10px;
60+
padding: 6px 10px;
6161
border: 1px solid red;
6262
display: table-cell;
6363
}
@@ -66,7 +66,7 @@
6666
border-radius: 3px;
6767
background: white;
6868
border: 1px solid red;
69-
padding: 10px;
69+
padding: 6px 10px;
7070
display: table-cell;
7171
}
7272
@@ -213,22 +213,16 @@
213213
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
214214
</div>
215215
<div class="modal-body">
216-
216+
<div class="row">
217217
<div class="form-group">
218-
<label for="title" class="col-sm-2 control-label">Title</label>
219-
<div class="col-sm-10">
218+
<label for="title" class="col-sm-12 control-label">Title</label>
219+
<div class="col-sm-12">
220220
<input type="text" name="title" class="form-control" id="title" placeholder="Title">
221221
</div>
222222
</div>
223223
<div class="form-group">
224-
<label for="description" class="col-sm-2 control-label">Description</label>
225-
<div class="col-sm-10">
226-
<input type="text" name="description" class="form-control" id="description" placeholder="Description">
227-
</div>
228-
</div>
229-
<div class="form-group">
230-
<label for="color" class="col-sm-2 control-label">Color</label>
231-
<div class="col-sm-10">
224+
<label for="color" class="col-sm-12 control-label">Color</label>
225+
<div class="col-sm-12">
232226
<select name="color" class="form-control" id="color">
233227
<option style="color:#0071c5;" value="#0071c5">&#9724; Dark blue</option>
234228
<option style="color:#40E0D0;" value="#40E0D0">&#9724; Turquoise</option>
@@ -240,14 +234,24 @@
240234
</select>
241235
</div>
242236
</div>
243-
<div class="form-group">
244-
<div class="col-sm-2">
245-
<label onclick="toggleCheck('check1');" class="label-off" for="check1" id="check1_label">
246-
Delete
247-
</label>
248-
<input class="nocheckbox" type="checkbox" id="check1" name="delete">
237+
</div>
238+
<div class="row">
239+
<div class="form-group">
240+
241+
<label for="description" class="col-12 control-label">Description</label>
242+
<div class="col-12">
243+
<input type="text" name="description" class="form-control" id="description" placeholder="Description">
244+
</div>
245+
</div>
246+
<div class="form-group" id="del">
247+
<label class="col-sm-12 control-label">Delete Event</label>
248+
<div class="col-sm-12">
249+
250+
<label onclick="toggleCheck('check1');" class="label-off" for="check1" id="check1_label">Delete</label>
251+
</div>
252+
<input class="nocheckbox" type="checkbox" id="check1" name="delete">
249253
</div>
250-
</div>
254+
</div>
251255
<script>
252256
function toggleCheck(check) {
253257
if ($('#'+check).is(':checked')) {
@@ -259,20 +263,24 @@ function toggleCheck(check) {
259263
}
260264
}
261265
</script>
266+
<div class="row">
262267
<div class="form-group">
263-
<label for="repeat1" class="col-sm-4 control-label">Recurrence Status</label>
264-
<div class="col-sm-10">
265-
<input type="text" name="repeat1" class="form-control" id="repeat1" placeholder="repeat1" readonly>
266-
</div>
267-
</div>
268+
<label for="repeat1" class="col-sm-12 control-label">Recurrence</label>
269+
<div class="col-sm-12">
270+
<input type="text" name="repeat1" class="form-control" id="repeat1" placeholder="repeat1" readonly>
271+
</div>
272+
</div>
268273
<div class="form-group" id="chk">
269-
<div class="col-sm-6">
274+
<label class="col-sm-12 control-label">Delete Recurrence</label>
275+
<div class="col-sm-12">
276+
270277
<label onclick="toggleCheck1('check2');" class="label-off" for="check2" id="check2_label">
271-
Delete Recurrence
278+
Delete
272279
</label>
280+
</div>
273281
<input class="nocheckbox" type="checkbox" id="check2" name="delete-repeat">
274282
</div>
275-
</div>
283+
</div>
276284
<script>
277285
function toggleCheck1(check) {
278286
if ($('#'+check).is(':checked')) {
@@ -356,6 +364,11 @@ function toggleCheck1(check) {
356364
$('#ModalEdit #description').val(event.description);
357365
$('#ModalEdit #color').val(event.color);
358366
$('#ModalEdit #repeat1').val(event.repeat);
367+
if (event.repeat == 'yes') {
368+
$('#chk').show();
369+
} else {
370+
$('#chk').hide();
371+
}
359372
$('#ModalEdit #count').val(event.count);
360373
$('#ModalEdit').modal('show');
361374
});

json/events.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[{"id":1,"title":"All Day Event","description":"some text for all day event","start":"2019-01-01","end":"2019-01-02","color":"#40E0D0"},{"id":2,"title":"Long Event","description":"some text for long event","start":"2019-01-07","end":"2019-01-10","color":"#FF0000"},{"id":3,"title":"Conference","description":"some text for conference","start":"2019-01-10","end":"2019-01-12","color":"#40E0D0"},{"id":4,"title":"Meeting","description":"some text for meeting","start":"2019-01-11 10:30:00","end":"2019-01-11 12:30:00","color":"#000"},{"id":5,"title":"Lunch","description":"some text for lunch","start":"2019-01-11 12:00:00","end":"2019-01-11 14:00:00","color":"#0071c5"},{"id":6,"title":"Short Event","description":"some text for short event","start":"2019-01-09 16:00:00","end":"2019-01-09 16:30:00","color":"#0071c5"},{"id":7,"title":"Dinner","description":"some text for dinner","start":"2019-01-11 16:00:00","end":"2019-01-11 17:30:00","color":"#0071c5"},{"id":8,"title":"Happy Hour","description":"some text for happy hour","start":"2019-01-11 17:30:00","end":"2019-01-11 19:30:00","color":"#0071c5"},{"id":9,"title":"Birthday Party","description":"some text for birthday party","start":"2019-01-13 09:00:00","end":"2019-01-13 12:00:00","color":"#FFD700"},{"id":10,"title":"Vacation","description":"some text for vacation","start":"2019-01-18","end":"2019-01-21","color":"#008000"},{"id":11,"title":"Double click to change","description":"some text for double click","start":"2019-01-22","end":"2019-01-23","color":"#000"},{"id":12,"title":"Shopping","description":"some text for shopping","start":"2019-01-31 17:30:00","end":"2019-01-31 18:30:00","color":"#FF8C00"}]
1+
{"0":{"id":1,"rid":1,"repeat":"no","title":"All Day Event","description":"some text for all day event","start":"2019-01-01","end":"2019-01-02","color":"#40E0D0"},"1":{"id":2,"rid":2,"repeat":"no","title":"Long Event","description":"some text for long event","start":"2019-01-07","end":"2019-01-10","color":"#FF0000"},"2":{"id":3,"rid":3,"repeat":"no","title":"Conference","description":"some text for conference","start":"2019-01-10","end":"2019-01-12","color":"#40E0D0"},"3":{"id":4,"rid":4,"repeat":"no","title":"Meeting","description":"some text for meeting","start":"2019-01-11 10:30:00","end":"2019-01-11 12:30:00","color":"#000"},"4":{"id":5,"rid":5,"repeat":"no","title":"Lunch","description":"some text for lunch","start":"2019-01-11 12:00:00","end":"2019-01-11 14:00:00","color":"#0071c5"},"5":{"id":6,"rid":6,"repeat":"no","title":"Short Event","description":"some text for short event","start":"2019-01-09 16:00:00","end":"2019-01-09 16:30:00","color":"#0071c5"},"6":{"id":7,"rid":7,"repeat":"no","title":"Dinner","description":"some text for dinner","start":"2019-01-11 16:00:00","end":"2019-01-11 17:30:00","color":"#0071c5"},"7":{"id":8,"rid":8,"repeat":"no","title":"Happy Hour","description":"some text for happy hour","start":"2019-01-11 17:30:00","end":"2019-01-11 19:30:00","color":"#0071c5"},"8":{"id":9,"rid":9,"repeat":"no","title":"Birthday Party","description":"some text for birthday party","start":"2019-01-13 09:00:00","end":"2019-01-13 12:00:00","color":"#FFD700"},"9":{"id":"10","rid":10,"repeat":"no","title":"Vacation","description":"some text for vacation","start":"2019-01-25","end":"2019-01-28","color":"#0071c5"},"10":{"id":11,"rid":11,"repeat":"no","title":"Double click to change","description":"some text for double click","start":"2019-01-22","end":"2019-01-23","color":"#000"},"11":{"id":12,"rid":12,"repeat":"no","title":"Shopping","description":"some text for shopping","start":"2019-01-31 17:30:00","end":"2019-01-31 18:30:00","color":"#FF8C00"},"12":{"id":13,"rid":13,"repeat":"yes","title":"Repeating Event","description":"You can change a series occurrence","start":"2019-01-03 20:00:00","end":"2019-01-03 20:30:00","color":"#000"},"13":{"id":14,"rid":13,"repeat":"yes","title":"Repeating Event","description":"This is a repeating event","start":"2019-01-10 20:00:00","end":"2019-01-10 20:30:00","color":"#008000"},"14":{"id":15,"rid":13,"repeat":"yes","title":"Repeating Event","description":"This is a repeating event","start":"2019-01-17 20:00:00","end":"2019-01-17 20:30:00","color":"#008000"},"16":{"id":17,"rid":14,"repeat":"yes","title":"All Day Repeating Event","description":"all day repeating event","start":"2019-01-14","end":"2019-01-15","color":"#FFD700"},"17":{"id":18,"rid":14,"repeat":"yes","title":"All Day Repeating Event","description":"all day repeating event","start":"2019-01-21","end":"2019-01-22","color":"#FFD700"}}

test.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
ini_set('display_errors', 1);
3+
ini_set('display_startup_errors', 1);
4+
error_reporting(E_ALL);
5+
6+
function getDatesInRange($dateFromString, $dateToString, $dow, $dowNum) {
7+
$dateFrom = new \DateTime($dateFromString);
8+
$dateTo = new \DateTime($dateToString);
9+
$dates = [];
10+
11+
if ($dateFrom > $dateTo) {
12+
return $dates;
13+
}
14+
15+
if ($dowNum != $dateFrom->format('N')) {
16+
$dateFrom->modify('next '. $dow);
17+
}
18+
19+
while ($dateFrom <= $dateTo) {
20+
$dates[] = $dateFrom->format('Y-m-d');
21+
$dateFrom->modify('+1 week');
22+
}
23+
24+
return $dates;
25+
}
26+
27+
$dateFromString = '2019-1-01';
28+
$dateToString = '2019-01-31';
29+
30+
$postDates = array(
31+
array('M',1,'monday'),
32+
array('T',2,'tuesday'),
33+
array('W',3,'wednesday'),
34+
array('R',4,'thursday'),
35+
array('F',5,'friday'),
36+
array('S',6,'saturday'),
37+
array('U',7,'sunday'),
38+
);
39+
40+
$num = 0;
41+
$post=array('1'=>'0','2'=>'2','3'=>'4');
42+
foreach ($post as $p) {
43+
$dowNum = $postDates[$p][1];
44+
$dow = $postDates[$p][2];
45+
$data = getDatesInRange($dateFromString, $dateToString, $dow, $dowNum);
46+
print_r(array_values($data));
47+
echo '<br>';
48+
echo 'Num of dates: ' . $count = count($data);
49+
echo '<br>';
50+
for ($x = 0; $x < $count; $x++) {
51+
echo 'Date: ' . $data[$x];
52+
echo '<br>';
53+
}
54+
echo 'Total date count: ' . $num += count($data);
55+
echo '<br>';
56+
}
57+
58+
59+
?>

0 commit comments

Comments
 (0)