aboutsummaryrefslogtreecommitdiffstats
path: root/include/datetime.php
diff options
context:
space:
mode:
authorHilmar R <u02@u29lx193>2021-01-23 15:24:24 +0100
committerHilmar R <u02@u29lx193>2021-01-23 15:24:24 +0100
commit67db1c6e9bc474c34cb10029794b64be8c85a393 (patch)
tree46619d97bafb88b4649629c0dfb370f1ddf6e5dc /include/datetime.php
parentabdf6f40a2712e31fe97d1d059bfea57a78be257 (diff)
downloadvolse-hubzilla-67db1c6e9bc474c34cb10029794b64be8c85a393.tar.gz
volse-hubzilla-67db1c6e9bc474c34cb10029794b64be8c85a393.tar.bz2
volse-hubzilla-67db1c6e9bc474c34cb10029794b64be8c85a393.zip
melt diff prod fork 4.6.2 air onto 5.2.1 to 5.2.2 DB 1241
Diffstat (limited to 'include/datetime.php')
-rw-r--r--include/datetime.php32
1 files changed, 32 insertions, 0 deletions
diff --git a/include/datetime.php b/include/datetime.php
index ef0927ea4..0b8722b4f 100644
--- a/include/datetime.php
+++ b/include/datetime.php
@@ -534,3 +534,35 @@ function update_birthdays() {
}
}
}
+
+/**
+ *
+ * Calculate a due by interval
+ * based on the current datetime the interval is added/subtracted
+ * @author Hilmar Runge
+ * @since 2020-02-20
+ * @param $duri the interval in the format n[n]i
+ * where n is a 1-2 digit numeric amount and i is a unit
+ * example $duri='1w' represents one week
+ * unit may be one of i(minutes), h(hours), d(days), w(weeks), m(months, y(years))
+ * @return array['due'] computed datetime in format 'Y-m-d H:i:s'
+ * ['durn'] the amount
+ * ['duru'] the unit
+ * or false
+ */
+ function calculate_adue($duri=false, $sign='+') {
+ if ( preg_match( '/^[0-9]{1,2}[ihdwmy]{1}$/', $duri ) && ($sign == '+' || $sign == '-') ) {
+ $duru = substr( $duri, -1);
+ $durn = substr( $duri, 0, -1);
+ $due = date( 'Y-m-d H:i:s', strtotime(
+ '+' . $durn . ' '
+ . str_replace( array(':i',':h',':d',':w',':m',':y'),
+ array('minutes', 'hours', 'days', 'weeks', 'months', 'years'),
+ ( ':'. $duru )
+ )
+ )
+ );
+ return array( 'durn' => $durn, 'duru' => $duru, 'due' => $due);
+ }
+ return false;
+ }