salix/db/versions/.archive/10459-chocolateMedeola/03-createFunctionMockTimeBa...

28 lines
640 B
MySQL
Raw Normal View History

DROP FUNCTION IF EXISTS `util`.`mockTimeBase`;
DELIMITER $$
CREATE DEFINER=`root`@`localhost` FUNCTION `util`.`mockTimeBase`(vIsUtc BOOL)
RETURNS datetime
DETERMINISTIC
BEGIN
/**
* Returns the date formatted to utc if vIsUtc or config.mocTz if not
*
* @param vIsUtc If date must be returned as UTC format
* @return The formatted mock time
*/
DECLARE vMockUtcTime DATETIME;
DECLARE vMockTz VARCHAR(255);
SELECT mockUtcTime, mockTz
INTO vMockUtcTime, vMockTz
FROM config
LIMIT 1;
IF vIsUtc OR vMockTz IS NULL THEN
RETURN vMockUtcTime;
ELSE
RETURN CONVERT_TZ(vMockUtcTime, '+00:00', vMockTz);
END IF;
END$$
DELIMITER ;