summaryrefslogtreecommitdiff
path: root/roundcubemail/program/include/rcube_shared.inc
diff options
context:
space:
mode:
authoralec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c>2012-04-19 07:42:19 +0000
committeralec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c>2012-04-19 07:42:19 +0000
commit392903aed8e7889b867e89669095ad473f9fb5bb (patch)
tree472a1a9e11999bb9bbf47163d0f37a077c37c8c8 /roundcubemail/program/include/rcube_shared.inc
parent2c79c401f0c4fc90ecd9fc06ae1eb5dbf8a3dca2 (diff)
- Improved ttl values handling
git-svn-id: https://svn.roundcube.net/trunk@6103 208e9e7b-5314-0410-a742-e7e81cd9613c
Diffstat (limited to 'roundcubemail/program/include/rcube_shared.inc')
-rw-r--r--roundcubemail/program/include/rcube_shared.inc34
1 files changed, 22 insertions, 12 deletions
diff --git a/roundcubemail/program/include/rcube_shared.inc b/roundcubemail/program/include/rcube_shared.inc
index b3911659e..176a46281 100644
--- a/roundcubemail/program/include/rcube_shared.inc
+++ b/roundcubemail/program/include/rcube_shared.inc
@@ -146,25 +146,23 @@ function clear_directory($dir_path)
/**
- * Create a unix timestamp with a specified offset from now.
+ * Returns number of seconds for a specified offset string.
*
- * @param string $offset_str String representation of the offset (e.g. 20min, 5h, 2days)
- * @param int $factor Factor to multiply with the offset
+ * @param string $str String representation of the offset (e.g. 20min, 5h, 2days, 1week)
*
- * @return int Unix timestamp
+ * @return int Number of seconds
*/
-function get_offset_time($offset_str, $factor=1)
+function get_offset_sec($str)
{
- if (preg_match('/^([0-9]+)\s*([smhdw])/i', $offset_str, $regs)) {
- $amount = (int)$regs[1];
+ if (preg_match('/^([0-9]+)\s*([smhdw])/i', $str, $regs)) {
+ $amount = (int) $regs[1];
$unit = strtolower($regs[2]);
}
else {
- $amount = (int)$offset_str;
+ $amount = (int) $str;
$unit = 's';
}
- $ts = time();
switch ($unit) {
case 'w':
$amount *= 7;
@@ -174,11 +172,23 @@ function get_offset_time($offset_str, $factor=1)
$amount *= 60;
case 'm':
$amount *= 60;
- case 's':
- $ts += $amount * $factor;
}
- return $ts;
+ return $amount;
+}
+
+
+/**
+ * Create a unix timestamp with a specified offset from now.
+ *
+ * @param string $offset_str String representation of the offset (e.g. 20min, 5h, 2days)
+ * @param int $factor Factor to multiply with the offset
+ *
+ * @return int Unix timestamp
+ */
+function get_offset_time($offset_str, $factor=1)
+{
+ return time() + get_offset_sec($offset_str) * $factor;
}