Here is a MySQL version of a function to convert from gregorian to discordian dates.
DELIMITER $
DROP FUNCTION IF EXISTS `test`.`toDiscordian` $
CREATE FUNCTION `toDiscordian`(gdate DATE) RETURNS varchar(50)
DETERMINISTIC
COMMENT 'Discordian Date Converter'
BEGIN
SET @year = EXTRACT(YEAR FROM gdate);
SET @dyear = @year + 1166;
SET @month = EXTRACT(MONTH FROM gdate);
SET @mday = DAYOFMONTH(gdate);
SET @yday = DAYOFYEAR(gdate);
SET @dseason = round(@yday/73);
CASE @dseason
WHEN 0 THEN SET @a_holiday = 'Mungday';
WHEN 1 THEN SET @a_holiday = 'Mojoday';
WHEN 2 THEN SET @a_holiday = 'Syaday';
WHEN 3 THEN SET @a_holiday = 'Zaraday';
WHEN 4 THEN SET @a_holiday = 'Maladay';
ELSE SET @a_holiday = 'Error in a_holiday';
END CASE;
CASE @dseason
WHEN 0 THEN SET @s_holiday = 'Chaoflux';
WHEN 1 THEN SET @s_holiday = 'Discoflux';
WHEN 2 THEN SET @s_holiday = 'Confuflux';
WHEN 3 THEN SET @s_holiday = 'Bureflux';
WHEN 4 THEN SET @s_holiday = 'Afflux';
ELSE SET @s_holiday = 'Error in s_holiday';
END CASE;
CASE @dseason
WHEN 0 THEN SET @name_season = 'Chaos';
WHEN 1 THEN SET @name_season = 'Discord';
WHEN 2 THEN SET @name_season = 'Confusion';
WHEN 3 THEN SET @name_season = 'Bureaucracy';
WHEN 4 THEN SET @name_season = 'The Aftermath';
ELSE SET @name_season = 'Error in name_season';
END CASE;
SET @dday=round((@yday-(73*@dseason))+1);
CASE mod(@dday, 10)
WHEN 1 THEN SET @dday = concat(@dday, 'st');
WHEN 2 THEN SET @dday = concat(@dday, 'nd');
WHEN 3 THEN SET @dday = concat(@dday, 'rd');
ELSE SET @dday = concat(@dday, 'th');
END CASE;
CASE mod(@yday, 5)
WHEN 0 THEN SET @dweekday = 'Sweetmorn';
WHEN 1 THEN SET @dweekday = 'Boomtime';
WHEN 2 THEN SET @dweekday = 'Pungenday';
WHEN 3 THEN SET @dweekday = 'Prickle-Prickle';
WHEN 4 THEN SET @dweekday = 'Setting Orange';
ELSE SET @dweekday = 'Error in dweekday';
END CASE;
CASE
WHEN @dday = 5 THEN SET @celebrate = concat(' Celebrate ', @a_holiday, '.');
WHEN @dday = 50 THEN SET @celebrate = concat(' Celebrate ', @s_holiday, '.');
WHEN (@month = 2 and @mday = 29) THEN SET @celebrate = ' Celebrate St. Tib''s Day.';
ELSE SET @celebrate = '';
END CASE;
SET @ddate = concat(@dweekday, ', ', @dday, ' ', @name_season, ', ', @dyear, '.', @celebrate);
RETURN @ddate;
END $$
DELIMITER ;
You can test it with a simple
SQL>SELECT toDiscordian(now());
It is certainly far from perfect, feel free to improve it and report errors.
Subscribe to:
Post Comments (Atom)
1 comment:
thanks for the awesome function
Post a Comment