r22918 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22917‎ | r22918 | r22919 >
Date:23:05, 11 June 2007
Author:david
Status:old
Tags:
Comment:
Converted to using real date deltas instead of the temporary arithmetic. Only thing left is to handle out-of-bounds conditions nicely.
Modified paths:
  • /branches/liquidthreads/extensions/LqtExtension.php (modified) (history)
  • /branches/liquidthreads/extensions/LqtModel.php (modified) (history)

Diff [purge]

Index: branches/liquidthreads/extensions/LqtExtension.php
@@ -673,21 +673,21 @@
674674 $ignore_dates = ! $r->getVal('lqt_archive_filter_by_date', true);
675675 $s = $r->getVal('lqt_archive_start');
676676 if ($s && ctype_digit($s) && strlen($s) == 6 && !$ignore_dates) {
677 - $this->start = "{$s}00000000";
678 - $where[] = 'thread_touched >= ' . $this->start;
 677+ $this->start = new Date( "{$s}01000000" );
 678+ $where[] = 'thread_touched >= ' . $this->start->text();
679679 }
680680 $e = $r->getVal('lqt_archive_end');
681681 if ($e && ctype_digit($e) && strlen($e) == 6 && !$ignore_dates) {
682 - $this->end = "{$e}00000000";
683 - $e += 1; // TODO addition on dates crossing years
684 - $where[] = 'thread_touched < ' . "{$e}00000000";
 682+ $end = new Date("{$e}01000000");
 683+ $this->end = $end->nextMonth();
 684+ $where[] = 'thread_touched < ' . $this->end->text();
685685 }
686686 if ( isset($this->start) && isset($this->end) ) {
687 - $annotations[] = "from $start to $end";
 687+ $annotations[] = "from {$this->start->text()} to {$this->end->text()}";
688688 } else if (isset($this->start)) {
689 - $annotations[] = "after $start";
 689+ $annotations[] = "after {$this->start->text()}";
690690 } else if (isset($this->end)) {
691 - $annotations[] = "before $end";
 691+ $annotations[] = "before {$this->end->text()}";
692692 }
693693
694694 $this->where = $where;
@@ -756,25 +756,23 @@
757757
758758 $one_month = '100000000';
759759 if( isset($this->start, $this->end) ) {
760 - var_dump($this->start, $this->end);
 760+ $older_end = $this->start->lastMonth();
 761+ $older_start = $older_end->moved( $this->start->delta( $this->end ) )->nextMonth();
761762
762 - $older_end = bcsub($this->start,$one_month);
763 - $older_start = bcsub($older_end, bcsub($this->end, $this->start));
 763+ $newer_start = $this->end;
 764+ $newer_end = $newer_start->moved( $this->end->delta( $this->start ) )->lastMonth();
764765
765 - $newer_start = bcadd($this->end, $one_month);
766 - $newer_end = bcadd($newer_start, bcsub( $this->end, $this->start ));
767 -
768 - var_dump($newer_start, $newer_end);
 766+ $older = $this->queryReplace(array(
 767+ 'lqt_archive_filter_by_date'=>'1',
 768+ 'lqt_archive_start' => substr($older_start->text(), 0, 6),
 769+ 'lqt_archive_end' => substr($older_end->text(), 0, 6) ));
 770+ $newer = $this->queryReplace(array(
 771+ 'lqt_archive_filter_by_date'=>'1',
 772+ 'lqt_archive_start' => substr($newer_start->text(), 0, 6),
 773+ 'lqt_archive_end' => substr($newer_end->text(), 0, 6) ));
 774+
769775 }
770 -
771 - $older = $this->queryReplace(array('lqt_archive_filter_by_date'=>'1',
772 - 'lqt_archive_start' => substr($older_start, 0, 6),
773 - 'lqt_archive_end' => substr($older_end, 0, 6) ));
774 - $newer = $this->queryReplace(array('lqt_archive_filter_by_date'=>'1',
775 - 'lqt_archive_start' => substr($newer_start, 0, 6),
776 - 'lqt_archive_end' => substr($newer_end, 0, 6) ));
777776
778 -
779777 $this->output->addHTML(<<<HTML
780778 <form id="lqt_archive_search_form" action="{$this->title->getLocalURL()}">
781779 <input type="hidden" name="lqt_show_archive" value="1">
Index: branches/liquidthreads/extensions/LqtModel.php
@@ -20,16 +20,39 @@
2121 $this->second = intval( substr( $text, 12, 2 ) );
2222 }
2323 function lastMonth() {
24 - $d = clone $this;
25 - $d->month -= 1;
26 - return $d;
 24+ return $this->moved('-1 month');
2725 }
 26+ function nextMonth() {
 27+ return $this->moved('+1 month');
 28+ }
 29+ function moved($str) {
 30+ $d = new DateTime($this->text());
 31+ $d->modify($str);
 32+ return new Date($d->format('YmdHis'));
 33+ }
2834 /* function monthString() {
2935 return sprintf( '%04d%02d', $this->year, $this->month );
3036 }*/
3137 static function monthString($text) {
3238 return substr($text, 0, 6);
3339 }
 40+
 41+ function delta( $o ) {
 42+ $t = clone $this;
 43+ $els = array('year', 'month', 'day', 'hour', 'minute', 'second');
 44+ $deltas = array();
 45+ foreach ($els as $e) {
 46+ $deltas[$e] = $t->$e - $o->$e;
 47+ $t->$e += $t->$e - $o->$e;
 48+ }
 49+
 50+ // format in style of DateTime::modify().
 51+ $result = "";
 52+ foreach( $deltas as $name => $val ) {
 53+ $result .= "$val $name ";
 54+ }
 55+ return $result;
 56+ }
3457 static function beginningOfMonth($yyyymm) { return $yyyymm . '00000000'; }
3558 static function endOfMonth($yyyymm) { return $yyyymm . '31235959'; }
3659 function text() {
@@ -40,9 +63,7 @@
4164 return new Date(wfTimestampNow());
4265 }
4366 function nDaysAgo($n) {
44 - $d = new DateTime($this->text());
45 - $d->modify("-$n days");
46 - return new Date( $d->format('YmdHis') );
 67+ return $this->moved("-$n days");
4768 }
4869 function midnight() {
4970 $d = clone $this;

Status & tagging log