technonaturalist

image link to hive image link to ko-fi

Backup malarky and prelimary theAbysmal scripts

posted on: Sunday, 18 December 2011 @ 3:17pm in

If this post disappears, it’s entirely my fault as I told the provider that this site could just be rolled back to the last backup (assuming the last backup he had was more recent than the one I had).

What happened with the backups? It’s a long and sordid story.

Actually it’s not that long, just slightly confusing. See the provider does scheduled backups as all decent providers should. But last month and earlier this month something very strange happened. Three of my sites (this one, Red Planet and WANLN) lost a month’s worth of posts. It’s entirely possible the other ones rolled back as well but these ones were the most noticable as they get updated constantly.

The backups were supposed to have been done about the time the rollbacks happened so my current hypothesis is that either the backup is happening and then it’s restoring from a backup for some bizarre reason, or it’s restoring from backup instead of backing up, or restoring from backup and then backing up. Hopefully not either of the last two as if that’s the case the stuff is gone for good and I’m hoping the lost posts can be merged back in from the backups into the current. Will see how we go. I’m really hoping it gets resolved sooner rather than later as my internet access is going to be sloooowwwwww from Christmas Island.

I recently hacked together a script to convert Gregorian dates to theAbysmal dates for use in AEfter Ragnarok. A couple of people on Diaspora* were interested in it, so I said I’d put it up here when I sorted the problems out. The problems aren’t sorted but it’s here anyway :)

<?php  
// set default timezone to utc
  date_default_timezone_set('UTC');
  
  // collect the date information from the form, otherwise use today
  // wonder if there's a shorter way to write this
  if (!empty($_POST['day_ce'])) {
    $day_ce = $_POST['day_ce'];
  }
  else {
    $_POST['day_ce'] = date('d');
    $day_ce = date('d');
  }
  
  if (!empty($_POST['month_ce'])) {
    $month_ce = $_POST['month_ce'];
  }
  else {
    $_POST['month_ce'] = date('n');
    $month_ce = date('n');
  }
  
  if (!empty($_POST['year_ce'])) {
    $year_ce = $_POST['year_ce'];
  }
  else {
    $_POST['year_ce'] = date('Y');
    $year_ce = date('Y');
  }

  // CE date from form or today
  $ce = date('l, d F Y', mktime(0, 0, 0, $month_ce, $day_ce, $year_ce)) . "CE"; 

  // converting the form values into time the computer can manipulate
  $ce_raw = mktime(0, 0, 0, $month_ce, $day_ce, $year_ce); 
  
  /*
   * finding out theAbysmal equivalent date
   * could not have done this bit without Josh's help
   */
  
  $zero_date = mktime(0, 0, 0, 12, 21, 2012); // new year day on the calendar
  $zero_day = date('z', mktime(0, 0, 0, 12, 22, 2012));
  
  // calculate abysmal year
    if (($month_ce == 12) && $day_ce -->20) { $year = date('Y', $ce_raw) - date('Y', $zero_date); } else { $year = (date('Y', $ce_raw) - date('Y', $zero_date)) - 1; } 
  
  // adjusting leap years 
  if ($year % 4 == 0) { $ly = 1; if ($year % 128 == 0) { $ly = 0; } } else { $ly = 0; } if (date('L', $ce_raw)) { $gly = 1; } else { $gly = 0; } $length_modifier = $gly + $ly; 
  
  // how many days in the year? +1 to make it an absolute value 
  $year_length = date('z', mktime(0, 0, 0, 12, 31, $year_ce)) + 1 + $ly - $gly; 
  
  // first work out what the year day number the supplied date is, add a day if it's a leap year 
  $gregorian_day_of_year = date('z', $ce_raw); 
  
  // how many days have passed since theAbysmal started, take off the extra days the leap year adds 
  $days_from_start = ($gregorian_day_of_year - $zero_day + $year_length - $gly) % $year_length; 
  
  // theAbysmal month converted to an integer 
  $month_number = intval($days_from_start / 28); 
  
  // what day in the month it is 
  $mday = $days_from_start % 28; 
  
  // lojban day names and assigning to month days 
  $days = array(
    'xundei' => array('0', '7', '14', '21'), 
    'najdei' => array('1', '8', '15', '22'), 
    'peldei' => array('2', '9', '16', '23'), 
    'ri\'ordei' => array('3', '10', '17', '24'),
    'cicnydei' =>; array('4', '11', '18', '25'), 
    'bladei' => array('5', '12', '19', '26'), 
    'zirdei' => array('6', '13', '20', '27'), 
  ); 
    
  foreach($days as $key =&gt; $value) { 
    if (in_array($mday, $value)) { 
        $weekday = $key; 
    } 
} 
    
// Tranquility calendar month names 
// the 14th "month" is a 2 day intercalary period for New Year Day and Leap Year Day 
$months = array(
    '0' => 'Archimedes', 
    '1' => 'Brahe', 
    '2' =>; 'Copernicus', 
    '3' =>; 'Darwin',
    '4' => 'Einstein', 
    '5' => 'Faraday',
    '6' => 'Galileo', 
    '7' => 'Hippocrates',
    '8' => 'Imhotep', 
    '9' => 'Jung', 
    '10' => 'Kepler', 
    '11' => 'Lavoisier', 
    '12' => 'Mendel', 
    '13' => '', 
    );
    
    foreach($months as $key =&gt; $value) { 
        if ($key == $month_number) { 
            $month = $value; 
        } 
    } 
    
    /* 
        * intercalary days 
        * 
        * check to see if it's December Solstice 
        * if it is, it's New Year Day 
        * if not, it's a weekday 
        * 
        * if it's a leap year and it's December Solstice 
        * it's Leap Year Day and everything is offset by 1 
    */ 
    
    $nyd = mktime(0, 0, 0, 12, 21, $year_ce); $lyd = mktime(0, 0, 0, 12, 20, $year_ce); 
    
    if ($month == '') { 
        $weekday = ''; 
        
        if ($ce_raw == $nyd) { 
            $mday = "New Year Day"; 
        } 
        
        if ($ly == 1 &amp;&amp; $ce_raw == $lyd) { 
            $mday = "Leap Year Day"; 
        } 
    } 
    
    $yrabs = abs($year); $yrlen = strlen($yrabs); 
    
    if ($ce_raw &lt; $zero_date) { 
        $sign = '-'; 
    } 
    elseif ($year == '0000') { 
        $sign = ''; 
    } 
    else {
        $sign = ''; 
    } 
    
    if ($yrlen == 1) { 
        $year = '000' . $yrabs; 
    } 
    elseif ($yrlen == 2) { 
        $year = '00' . $yrabs; 
    }
    elseif ($yrlen == 3) { 
        $year = '0' . $yrabs; 
    }
?>

And a form to convert any date (defaults to today):

[form no longer works because no more dynamic site so here’s the code]

<form id="converter" method="post">
    <label>Day:</label> <input name="day_ce" type="number" /> 
    <label>Month:</label>
        <select name="month_ce">
            <option value="01">January</option>
            <option value="02">February</option>
            <option value="03">March</option>
            <option value="04">April</option>
            <option value="05">May</option>
            <option value="06">June</option>
            <option value="07">July</option>
            <option value="08">August</option>
            <option value="09">September</option>
            <option value="10">October</option>
            <option value="11">November</option>
            <option value="12">December</option> 
        </select> 
    <label>Year:</label> <input name="year_ce" type="number" /> <input type="submit" />
</form>

Gregorian: <?php echo $ce; ?><br />
theAbysmal: <?php echo $sign . $year . ' ' . $month . ' ' . $mday . ' ' . ' ' . $weekday . ' '; ?>

It’s a bit quick and dirty and probably hacky and could use improvements, so suggestions and improvements welcome. I’m a cheap module hack, still learning :) To use it whack it in a php file. If you don’t like the names of the months and days, change ’em in the arrays. Officially theAbysmal weeks start on Saturday.

I also converted it into a Drupal module. Today’s converted date can be seen at the top of the sidebar, the post converted date is embedded under the title. The tags have been moved to the bottom of the post. The shortened date notation is my invention, as is the usage of lojban words for the week day names and Tranquility months for the month names. The actual theAbysmal Calendar uses the current weekday names and I think just numbers (Month 0, Month 1 etc) for month names.