Skip to content

Instantly share code, notes, and snippets.

@duck1123
Created September 25, 2015 03:51
Show Gist options
  • Save duck1123/0b5240f47bf165c4217c to your computer and use it in GitHub Desktop.
Save duck1123/0b5240f47bf165c4217c to your computer and use it in GitHub Desktop.
DDate in JS
// title: Discordian Date Converter
// filename: ddate.js
// author: Lord Anas Mystosis Nebuchadnezzar XXXVII
// URL: http://kronkltd.net/
// Format Key:
// d - Day of the month, 2 digits with leading zeros (01 - 73)
// D - A textual representation of a day, three letters (Swt, Bmt, Pun, Pri, Set)
// F - A full textual representation of a month (Chaos, Discord, Confusion, Bureaucracy, Aftermath)
// j - Day of the month without leading zeros (1 - 73)
// l - A full textual representation of the day of the week (Sweetmorn, Boomtime, Pungenday, Prickle-Prickle, Setting Orange)
// m - Numeric representation of a month, with leading zeros (01 - 05)
// M - A short textual representation of a month, three letters (Cha, Dis, Con, Bur, Aft)
// n - Numeric representation of a month, without leading zeros (1 - 5)
// w - Numeric representation of the day of the week (0 for Sweetmorn through 4 for Setting Orange)
// Y - A full numeric representation of a year, 4 digits (eg. 3170)
// y - A two digit representation of a year (eg. 70)
function DDate(format, timestamp)
{
var output = "";
var gMonth = timestamp.getMonth() + 1;
var gDay = timestamp.getDate();
var gYear = timestamp.getFullYear();
var dYear = gYear + 1166;
var nDay = 0;
var monthNum = new Array(0, 31, 59, 90, 120, 150, 181, 212, 242, 273, 303, 334);
var dayInYear = monthNum[gMonth - 1] + gDay - 1;
var dMonth = Math.floor(dayInYear / 73) + 1;
var dDay = dayInYear - ((dMonth - 1) * 73) + 1;
var daynumber = (dayInYear % 5) + 1;
var dayName3 = new Array('Swt', 'Bmt', 'Pun', 'Pri', 'Set');
var monthName3 = new Array('Cha', 'Dis', 'Con', 'Bur', 'Aft')
var dayNameFull = new Array('Sweetmorn', 'Boomtime', 'Pungenday', 'Prickle-Prickle', 'Setting Orange');
var monthNameFull = new Array('Chaos', 'Discord', 'Confusion', 'Bureaucracy', 'Aftermath');
for (x = 0; x < format.length; x++)
{
switch (format[x])
{
case 'd':
{
if (dDay < 10)
{
output += '0' + dDay;
}
else
{
output += dDay;
}
break;
}
case 'D':
{
output += dayName3[daynumber - 1];
break;
}
case 'F':
{
output += monthNameFull[dMonth -1];
break;
}
case 'j':
{
output += dDay;
break;
}
case 'l':
{
output += dayNameFull[daynumber - 1];
break;
}
case 'm':
{
output += '0' + dMonth;
break;
}
case 'M':
{
output += monthName3[dMonth - 1];
break;
}
case 'n':
{
output += dMonth;
break;
}
case 'w':
{
output += (daynumber - 1);
break;
}
case 'Y':
{
output += dYear;
break;
}
case 'y':
{
output += (dYear % 100);
break;
}
default:
{
output += format[x];
break;
}
}
}
document.writeln(output);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment