-
Notifications
You must be signed in to change notification settings - Fork 0
/
ddcalc.php
executable file
·82 lines (63 loc) · 2.45 KB
/
ddcalc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
// DAY AND DATE CALCULATOR
if ($_POST["CalcType"] == "Days") { //IF SOLVING FOR DAYS
//CHECK USER INPUT
if (empty($_POST["Day1"]) || empty($_POST["Month1"]) || empty($_POST["Year1"]) || empty($_POST["Day2"]) || empty($_POST["Month2"]) || empty($_POST["Year2"])) {
die(printf("Error: DayCalc empty field"));
}
$day1 = (integer) $_POST["Day1"];
$month1 = (integer) $_POST["Month1"];
$year1 = (integer) $_POST["Year1"];
$day2 = (integer) $_POST["Day2"];
$month2 = (integer) $_POST["Month2"];
$year2 = (integer) $_POST["Year2"];
if ($month1 < 1 || $month1 > 12) {
die(printf("Error: invalid value for \"Month1\""));
} elseif ($day1 < 1 || $day1 > 31) {
die(printf("Error: invalid value for \"Day1\""));
} elseif ($month2 < 1 || $month2 > 12) {
die(printf("Error: invalid value for \"Month2\""));
} elseif ($day2 < 1 || $day2 > 31) {
die(printf("Error: invalid value for \"Day2\""));
}
//PROCESS INPUT
$date1 = new DateTime($year1."-".$month1."-".$day1." 12:00:00+0000");
$date2 = new DateTime($year2."-".$month2."-".$day2." 12:00:00+0000");
$sec1 = $date1->format('U'); // epoch time of the requested date
$sec2 = $date2->format('U'); // epoch time of the requested date
if ($sec1 > $sec2) {
$deltasec1 = ( $sec1 - $sec2 );
} elseif ($sec1 < $sec2) {
$deltasec1 = ( $sec2 - $sec1 );
}
//CONVERT SEC TO DAYS
$numdays = (integer) ( $deltasec1 / 86400 );
printf($numdays);
} elseif ($_POST["CalcType"] == "Date") { //IF SOLVING FOR DATE
//CHECK USER INPUT
if (empty($_POST["Day3"]) || empty($_POST["Month3"]) || empty($_POST["Year3"]) || empty($_POST["DayNum"]) || empty($_POST["TimeDir"])) {
die(printf("Error: DateCalc empty field"));
}
$day3 = (integer) $_POST["Day3"];
$month3 = (integer) $_POST["Month3"];
$year3 = (integer) $_POST["Year3"];
$daynum = (integer) $_POST["DayNum"];
$timedir = $_POST["TimeDir"];
if ($month3 < 1 || $month3 > 12) {
die(printf("Error: invalid value for \"Month3\""));
} elseif ($day3 < 1 || $day3 > 31) {
die(printf("Error: invalid value for \"Day3\""));
}
//PROCESS INPUT
$date3 = new DateTime($year3."-".$month3."-".$day3." 12:00:00+0000");
$sec3 = $date3->format('U'); // epoch time of the requested date
$sec4 = ( $daynum * 86400 ); // number of days requested by the user
if ($timedir == "Past") {
$deltasec3 = ( $sec3 - $sec4 );
} elseif ($timedir == "Future") {
$deltasec3 = ( $sec3 + $sec4 );
}
$date_result = date("m/d/Y", $deltasec3);
printf($date_result);
}
?>