/**
 * Get limit from database for specified date.
 *
 * @param null|string $date date from which limit will be obtained, leave null for current day.
 *
 * @return double daily limit.
 */
function operations_ledcoin_daily_limit($date = NULL)
{
    if ($date === NULL) {
        $date = date('Y-m-d');
    } else {
        if (!preg_match('/^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}$/', $date)) {
            return 0.0;
        }
        list($year, $month, $day) = explode('-', $date);
        if (!checkdate($month, $day, $year)) {
            return 0.0;
        }
    }
    $limit = new Limit();
    $limit->get_where(array('date' => $date));
    if ($limit->exists()) {
        return (double) $limit->daily_limit;
    }
    return 0.0;
}