date

PHP, strtotime and weeks over new year problems

Having problems with navigating over new year with weeks and think it's a bug? You are not alone, a friend of mine also thought so :-) There is a problem how to deal with starting days of week, Sunday or Monday causing the problem.

Problem: based on a date adding a week or 7 days (+1 week or +7 days) causing "20121224 +1week" end up on "20121231" if you set "Ymd" but if you go for "YW" you get "201201". If you instead use the ISO year "o" you will get the right year.

Workaround warnings like "It is not safe to rely on the system's timezone settings..." using strtotime() and date()

When running cron.php from CLI you might get a warning like "It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CEST/2.0/DST' instead ..."

Best solution is to set the time zone in the CLI version of php.ini, suggested in http://drupal.org/node/615438#comment-2195208

Add a monthly datepicker with jQuery - separate script

This script adds a month-year picker to a text field, and works better than a modification of jQuery datepicker.

<?php
drupal_add_js
(drupal_get_path('module', 'jquery_ui') .'/jquery.ui/ui/jquery.mtz.monthpicker.js');

$sub_script = "$(document).ready(function () {
         $('.add-datepicker-y-m').monthpicker({
            'pattern': 'mm/yyyy'
          })
        }); "
;

drupal_add_js($script, 'inline', 'footer');
?>

Source: https://github.com/lucianocosta/jquery.mtz.monthpicker