Page 1 of 1

Discordian Date

Posted: Sun Sep 03, 2006 1:21 pm
by Euronymous
I want a discordian date format in my blog, but all i found is this php script and yea... i found no way to use it in my blog, so... anybody? :)

Code: Select all

<?
/* $ DVCS ID: $jer|,523/lhos,KYTP!41023161\b"?" <<= DO NOT DELETE! */

/* ddate.c .. converts boring normal dates to fun Discordian Date -><-
    original incarnation written the 65th day of The Aftermath in the
    Year of Our Lady of Discord 3157 by Druel the Chaotic aka Jeremy Johnson
    aka mpython@gnu.ai.mit.edu.
    Majorly hacked, extended and bogotified/debogotified on
    Sweetmorn, Bureaucracy 42, 3161 YOLD, by Lee H:. O:. Smith, KYTP,
    aka Andrew Bulhak, aka acb@zikzak.net

    PHP class-version hack by vesel aka Jurgen Schwietering
    aka jurgen@schwietering.com on
    Boomtime, Discord 14, 3168 YOLD

    usage:
    class constructor
      ddate($moe=0, $larry=0, $curly=0, $format=defFormat);
      (note: m d y format)

    getDDate(); // returns the datestring

    todayDdate(); // get the old immediate format
    echo "<BR>";

*/
/*
 * @author: original c-code Jeremy Johnson, rewritten Jurgen Schwietering
 * @description-en: Create Discordian Date
 * @class: Date
 * @title: Create Discordian Date String
 */



class ddate{

    /* configuration options  VVVVV   READ THIS!!! */

    /* these are original formats, replace in ddate() if you would like to use them as default
    */
    var $default_fmt = "%{%A, %B %d%}, %Y YOLD";
    var $default_immediate_fmt="Today is %{%A, the %e day of %B%} in the YOLD %Y%N%nCelebrate %H";

    /* PRAISE_BOB has been removed: JS */


    var $day_long = array("Sweetmorn", "Boomtime", "Pungenday", "Prickle-Prickle", "Setting Orange");
    var $day_short = array("SM","BT","PD","PP","SO");
    var $season_long = array("Chaos", "Discord", "Confusion", "Bureaucracy", "The Aftermath");
    var $season_short = array("Chs", "Dsc", "Cfn", "Bcy", "Afm");

    var $holyday= array(
        array("Mungday", "Chaoflux"),
        array("Mojoday", "Discoflux"),
        array("Syaday",  "Confuflux"),
        array("Zaraday", "Bureflux"),
        array("Maladay", "Afflux")
    );


    var $excl =array(
        "Hail Eris!", "All Hail Discordia!", "Kallisti!", "Fnord.", "Or not.",
        "Wibble.", "Pzat!", "P'tang!", "Frink!",
        /* randomness, from the Net and other places. Feel free to add (after
         * checking with the relevant authorities, of course).
         */
        "Hail Eris, Hack PHP!",
        "Grudnuk demand sustenance!",
        "Keep the Lasagna flying!",
        "Umlaut Zebra über alles!"
    );

    var $schwa; // where to store the calculated date

    // private functions:
    function DY($y) {
        return $y+1166;
    }

    function ending($i) {
        return ($i%10==1)?"st":($i%10==2?"nd":($i%10==3?"rd":"th"));
    }

    function leapp($i) {
        return (!(DY($i)%4))&&((DY($i)%100)||(!(DY($i)%400)));
    }

    function format($fmt, $dt) {
        $wibble="";
        $tib_start=-1;
        $tib_end=0;
        $fmtlen=strlen($fmt);

        // first, find extents of St. Tib's Day area, if defined
        for($i=0; $i<$fmtlen; $i++) {
            if($fmt{$i}=='%') {
                switch($fmt{$i+1}) {
                    case 'A':
                    case 'a':
                    case 'd':
                    case 'e':
                        if($tib_start>0)
                            $tib_end=$i+1;
                        else
                            $tib_start=$i;
                        break;
                    case '{':
                        $tib_start=$i;
                        break;
                    case '}':
                        $tib_end=$i+1;
                        break;
                }
            }
        }
        // now do the formatting
        $buf="";

        for($i=0; $i<$fmtlen; $i++) {
            if(($i==$tib_start) && ($dt["day"]==-1)) {
                /* handle St. Tib's Day */
                $buf.="St. Tib's Day";
                $i=$tib_end;
            } else {
                if($fmt[$i]=='%') {
                    $i++;
                    switch($fmt[$i]) {
                        case 'A': $wibble=$this->day_long[$dt["yday"]%5]; break;
                        case 'a': $wibble=$this->day_short[$dt["yday"]%5]; break;
                        case 'B': $wibble=$this->season_long[$dt["season"]]; break;
                        case 'b': $wibble=$this->season_short[$dt["season"]]; break;
                        case 'd': $snarf=sprintf("%d", $dt["day"]+1); $wibble=$snarf; break;
                        case 'e': $snarf=sprintf("%d%s", $dt["day"]+1, $this->ending($dt["day"]+1));
                                    $wibble=$snarf;
                                    break;
                        case 'H': if ($dt["day"]==4||$dt["day"]==49)
                                    $wibble = $this->holyday[$dt["season"]][$dt["day"]==49];
                                  break;
                        case 'N': if($dt["day"]!=4&&$dt["day"]!=49)
                                    return $buf;
                        case 'n': $buf.='\n'; break;
                        case 't': $buf.='\t'; break;
                        case 'Y': $snarf=sprintf("%d", $dt["year"]); $wibble=$snarf; break;
                        case '.': $wibble=$this->excl[rand(0,count($excl)-1)];
                                break;
                        case '%': $wibble='%'; break;
                        default:
                            $wibble=""; // ignore
                            break;
                    }
                    if($wibble) {
                        $buf.=$wibble;
                    }
                } else {
                    $buf.=$fmt[$i];
                }
            }
        }
        return $buf;
    }

    // I guess that in PHP we could make this much more short. JS

    function makeday($imonth,$iday,$iyear) /*i for input */
    {
        $cal = array(31,28,31,30,31,30,31,31,30,31,30,31);
        $dayspast=0;

        $imonth--;
        $funkyChickens["year"]= $iyear+1166;
        while($imonth>0) {
            $dayspast+=$cal[--$imonth];
        }
        $funkyChickens["day"]=$dayspast+$iday-1;
        $funkyChickens["season"]=0;
        if(($funkyChickens["year"]%4)==2) {
            if ($funkyChickens["day"]==59)
                $funkyChickens["day"]=-1;
        }
        $funkyChickens["yday"]=$funkyChickens["day"];
        while($funkyChickens["day"]>=73) {
            $funkyChickens["season"]++;
            $funkyChickens["day"]-=73;
        }
        return $funkyChickens;
    }


    function convert($nday, $nyear) // returns assoc array [year,day,season,yday]
    {
        $funkyChickens["year"] = $nyear+3066;
        $funkyChickens["day"]=$nday;
        $funkyChickens["season"]=0;
        if (($funkyChickens["year"]%4)==2)
        {if ($funkyChickens["day"]==59)
        $funkyChickens["day"]=-1;
         else if ($funkyChickens["day"] >59)
           $funkyChickens["day"]-=1;
        }
        $funkyChickens["yday"]=$funkyChickens["day"];
        while ($funkyChickens["day"]>=73){
            $funkyChickens["season"]++;
            $funkyChickens["day"]-=73;
        }
        return $funkyChickens;
    }

    function ddate($moe=0, $larry=0, $curly=0, $format="%{%A, %B %d%}, %Y YOLD") {
        if ($moe==0) {
            $bob=date("z");
            $raw=date("Y")-1900;
            $hastur=$this->convert($bob,$raw);
        }
        else
            $hastur=$this->makeday($larry, $moe, $curly);
        $this->schwa=$this->format($format, $hastur);
        return $this->schwa;
    }

    // public functions:

    function getDDate() {
        return $this->schwa;
    }

    // get the old ddate string for today
    function todayDdate($format="Today is %{%A, the %e day of %B%} in the YOLD %Y%N%nCelebrate %H") {
        $bob=date("z"); // eris->tm_yday; // days since Jan 1.
        $raw=date("Y")-1900; // eris->tm_year; // years since 1900
        $hastur=$this->convert($bob,$raw);
        $this->schwa=$this->format($format, $hastur);
        return $this->schwa;
    }

}

// some short test
$dd=new ddate();
echo $dd->getDDate();
echo "<BR>";
echo $dd->ddate(6,4,1964); // already created an object, so use it again.
echo "<BR>";
echo $dd->todayDdate(); // the old immidiate format
echo "<BR>";
?>
http://en.wikipedia.org/wiki/Discordian_calendar

Posted: Mon Sep 04, 2006 5:52 am
by judebert
Holy cow. Now I have something new to look up.

You can put that php in your template's config.inc.php file (if it doesn't have one, you can make one). You can turn it into a Smarty modifier with code like this. Then you just modify the template so wherever it calls |@formatTime it instead calls |discordianDate (or whatever you decided to call it).

Posted: Mon Sep 04, 2006 8:08 pm
by Euronymous
sounds easy, but I have no experience with smarty and its broke my local template :(

Code: Select all

<?php
$serendipity['smarty']->register_function('discordiandate', 'discordiandate');

function discordiandate(%{%A, %B %d%}, %Y YOLD) 
return str_replace('formatime', 'discordiandate', $str); 
...
something like this?

Posted: Mon Sep 04, 2006 9:35 pm
by garvinhicking
Hi!

Short answer: No. :)

Long answer: http://nopaste.php-q.net/237429

Putting that in your templates config.inc.php allows you to use {$entry.timestamp|discordianDate}.

NOTE WELL: The code you pasted above is a total blast of nonsense. Reading the cost is virtually impossible. If it does not work, complain at the original authors. Their code is not readable at all, my hat was blasting off while trying to figure out how to format a string according to a timestamp.

A funny dateformat is okay, but WTF can't the sourcecode be legible? What is that ugly code good for? It could have been done with readable and more optimized code, the conversion itself to that dateformat is straight ahead easy.

Best regards,
Garvin

Posted: Tue Sep 05, 2006 2:36 am
by judebert
I didn't even bother to try to read it. Looks like Discordianism is based on principles of chaos. Perhaps it's against their religion to write organized code.

Posted: Fri Sep 08, 2006 5:11 pm
by Euronymous
try it local, get an
Fatal error: Smarty error: [in file:D:/HP/xampp/htdocs/serendipity/templates/Rosenbluth/entries.tpl line 12]: [plugin] (secure mode) modifier 'discordianDate' is not allowed (Smarty_Compiler.class.php, line 1908) in D:\HP\xampp\htdocs\serendipity\bundled-libs\Smarty\libs\Smarty.class.php on line 1088
so, what should i do?

Posted: Fri Sep 08, 2006 5:19 pm
by garvinhicking
Hi!

Sounds like you didn't properly insert all the required register_function code into your templates config.inc.php?

Regards,
Garvin

Posted: Fri Sep 08, 2006 5:48 pm
by Euronymous
mhm, take it 1:1 from your linked code

Posted: Fri Sep 08, 2006 8:13 pm
by garvinhicking
Hi!

Oh. Try to use "register_modifier" instead of "register_function". :)

Regards,
Garvin

Posted: Sat Sep 09, 2006 6:41 pm
by Euronymous
Okay, the calender is broken and the thing only works in my template, but it works... thank you...

so, the sidebar, plugins, etc.

something like

Code: Select all

function replace_date($str) {
  return str_replace('|@formatTime:DATE_FORMAT_ENTRY', '|discordianDate', $str);
}
$serendipity['smarty']->register_modifier('replace_date','replace_date');

Posted: Mon Sep 11, 2006 4:52 pm
by judebert
Are you trying to get a Discordian date for everything? Like adding a new choice to Gregorian and Jalali?

Posted: Tue Sep 12, 2006 3:53 am
by Oliver
judebert wrote:Are you trying to get a Discordian date for everything? Like adding a new choice to Gregorian and Jalali?
that would be great :D

Posted: Tue Sep 12, 2006 4:52 pm
by Euronymous
judebert

mhm, i think it's a learnproject for me, but when its finished, it could be a part of the source, why not...

Posted: Sun Oct 08, 2006 4:58 pm
by Euronymous
Now it's working, here is a Version in German, so, how is the way to make a plugin of it? I'm so helpless when there is nothing i could... hmm "learn from" :D

Code: Select all

<?php
/*
 * @author: original c-code Jeremy Johnson, rewritten Jurgen Schwietering
 * @description-en: Create Discordian Date
 * @class: Date
 * @title: Create Discordian Date String
 */

class ddate{

    /* configuration options  VVVVV   READ THIS!!! */

    /* these are original formats, replace in ddate() if you would like to use them as default
    */
    var $default_fmt = "%{%A, %B %d%}, Year of Our Lady of Discord %Y";
    var $default_immediate_fmt="Today is %{%A, the %e day of %B%} in the YOLD %Y%N%nCelebrate %H";

    /* PRAISE_BOB has been removed: JS */


    var $day_long = array("Süßmorg", "Blühzeit", "Stichtag", "Juck-Juck", "Wird Orange");
    var $day_short = array("SM","BZ","ST","JJ","WO");
    var $season_long = array("des Chaos", "des Discord", "der Verwirrung", "der Bürokratie", "der Endzeit");
    var $season_short = array("Chs", "Dsc", "Vwg", "Bür", "End");

    var $holyday= array(
        array("Mungtag", "Chaoflux"),
        array("Mojotag", "Discoflux"),
        array("Syatag",  "Verwirrflux"),
        array("Zaratag", "Büroflux"),
        array("Malatag", "Endflux")
    );


    var $excl =array(
        "Hail Eris!", "All Hail Discordia!", "Kallisti!", "Fnord.", "Or not.",
        "Wibble.", "Pzat!", "P'tang!", "Frink!",
        /* randomness, from the Net and other places. Feel free to add (after
         * checking with the relevant authorities, of course).
         */
        "Hail Eris, Hack PHP!",
        "Grudnuk demand sustenance!",
        "Keep the Lasagna flying!",
        "Umlaut Zebra über alles!"
    );

    var $schwa; // where to store the calculated date

    // private functions:
    function DY($y) {
        return $y+1166;
    }

    function ending($i) {
        return ($i%10==1)?"st":($i%10==2?"nd":($i%10==3?"rd":"th"));
    }

    function leapp($i) {
        return (!(DY($i)%4))&&((DY($i)%100)||(!(DY($i)%400)));
    }

    function format($fmt, $dt) {
        $wibble="";
        $tib_start=-1;
        $tib_end=0;
        $fmtlen=strlen($fmt);

        // first, find extents of St. Tib's Day area, if defined
        for($i=0; $i<$fmtlen; $i++) {
            if($fmt{$i}=='%') {
                switch($fmt{$i+1}) {
                    case 'A':
                    case 'a':
                    case 'd':
                    case 'e':
                        if($tib_start>0)
                            $tib_end=$i+1;
                        else
                            $tib_start=$i;
                        break;
                    case '{':
                        $tib_start=$i;
                        break;
                    case '}':
                        $tib_end=$i+1;
                        break;
                }
            }
        }
        // now do the formatting
        $buf="";

        for($i=0; $i<$fmtlen; $i++) {
            if(($i==$tib_start) && ($dt["day"]==-1)) {
                /* handle St. Tib's Day */
                $buf.="St. Tib's Tag";
                $i=$tib_end;
            } else {
                if($fmt[$i]=='%') {
                    $i++;
                    switch($fmt[$i]) {
                        case 'A': $wibble=$this->day_long[$dt["yday"]%5]; break;
                        case 'a': $wibble=$this->day_short[$dt["yday"]%5]; break;
                        case 'B': $wibble=$this->season_long[$dt["season"]]; break;
                        case 'b': $wibble=$this->season_short[$dt["season"]]; break;
                        case 'd': $snarf=sprintf("%d", $dt["day"]+1); $wibble=$snarf; break;
                        case 'e': $snarf=sprintf("%d%s", $dt["day"]+1, $this->ending($dt["day"]+1));
                                    $wibble=$snarf;
                                    break;
                        case 'H': if ($dt["day"]==4||$dt["day"]==49)
                                    $wibble = $this->holyday[$dt["season"]][$dt["day"]==49];
                                  break;
                        case 'N': if($dt["day"]!=4&&$dt["day"]!=49)
                                    return $buf;
                        case 'n': $buf.='\n'; break;
                        case 't': $buf.='\t'; break;
                        case 'Y': $snarf=sprintf("%d", $dt["year"]); $wibble=$snarf; break;
                        case '.': $wibble=$this->excl[rand(0,count($excl)-1)];
                                break;
                        case '%': $wibble='%'; break;
                        default:
                            $wibble=""; // ignore
                            break;
                    }
                    if($wibble) {
                        $buf.=$wibble;
                    }
                } else {
                    $buf.=$fmt[$i];
                }
            }
        }
        return $buf;
    }

    // I guess that in PHP we could make this much more short. JS

    function makeday($imonth,$iday,$iyear) /*i for input */
    {
        $cal = array(31,28,31,30,31,30,31,31,30,31,30,31);
        $dayspast=0;

        $imonth--;
        $funkyChickens["year"]= $iyear+1166;
        while($imonth>0) {
            $dayspast+=$cal[--$imonth];
        }
        $funkyChickens["day"]=$dayspast+$iday-1;
        $funkyChickens["season"]=0;
        if(($funkyChickens["year"]%4)==2) {
            if ($funkyChickens["day"]==59)
                $funkyChickens["day"]=-1;
        }
        $funkyChickens["yday"]=$funkyChickens["day"];
        while($funkyChickens["day"]>=73) {
            $funkyChickens["season"]++;
            $funkyChickens["day"]-=73;
        }
        return $funkyChickens;
    }


    function convert($nday, $nyear) // returns assoc array [year,day,season,yday]
    {
        $funkyChickens["year"] = $nyear+3066;
        $funkyChickens["day"]=$nday;
        $funkyChickens["season"]=0;
        if (($funkyChickens["year"]%4)==2)
        {if ($funkyChickens["day"]==59)
        $funkyChickens["day"]=-1;
         else if ($funkyChickens["day"] >59)
           $funkyChickens["day"]-=1;
        }
        $funkyChickens["yday"]=$funkyChickens["day"];
        while ($funkyChickens["day"]>=73){
            $funkyChickens["season"]++;
            $funkyChickens["day"]-=73;
        }
        return $funkyChickens;
    }

    function ddate($moe=0, $larry=0, $curly=0, $format="%{%A, %d. Tag %B%} im Jahr unserer Dame der Zwietracht %Y") {
        if ($moe==0) {
            $bob=date("z");
            $raw=date("Y")-1900;
            $hastur=$this->convert($bob,$raw);
        }
        else
            $hastur=$this->makeday($larry, $moe, $curly);
        $this->schwa=$this->format($format, $hastur);
        return $this->schwa;
    }

    // public functions:

    function getDDate() {
        return $this->schwa;
    }

    // get the old ddate string for today
    function todayDdate($format="Today is %{%A, the %e day of %B%} in the YOLD %Y%N%nCelebrate %H") {
        $bob=date("z"); // eris->tm_yday; // days since Jan 1.
        $raw=date("Y")-1900; // eris->tm_year; // years since 1900
        $hastur=$this->convert($bob,$raw);
        $this->schwa=$this->format($format, $hastur);
        return $this->schwa;
    }

}

function discordianDate($timestamp = null) {
    $dd = new ddate();
    if ($timestamp == null) {
        $timestamp = time();
    }
    $dd->getDDate();
    return $dd->ddate(date('d', $timestamp), date('m', $timestamp), date('Y', $timestamp));
}

$serendipity['smarty']->register_modifier('discordianDate', 'discordianDate');

function replace_date($str) {
  return str_replace('|@formatTime:DATE_FORMAT_ENTRY', '|discordianDate', $str);
}
$serendipity['smarty']->register_modifier('replace_date','replace_date');
?>

Posted: Mon Oct 09, 2006 1:08 pm
by garvinhicking
Hi!

It would look like this:

http://nopaste.php-q.net/245502

(untested)

Regards,
Garvin