Index: branches/liquidthreads/extensions/LqtExtension.php |
— | — | @@ -673,21 +673,21 @@ |
674 | 674 | $ignore_dates = ! $r->getVal('lqt_archive_filter_by_date', true); |
675 | 675 | $s = $r->getVal('lqt_archive_start'); |
676 | 676 | 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(); |
679 | 679 | } |
680 | 680 | $e = $r->getVal('lqt_archive_end'); |
681 | 681 | 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(); |
685 | 685 | } |
686 | 686 | if ( isset($this->start) && isset($this->end) ) { |
687 | | - $annotations[] = "from $start to $end"; |
| 687 | + $annotations[] = "from {$this->start->text()} to {$this->end->text()}"; |
688 | 688 | } else if (isset($this->start)) { |
689 | | - $annotations[] = "after $start"; |
| 689 | + $annotations[] = "after {$this->start->text()}"; |
690 | 690 | } else if (isset($this->end)) { |
691 | | - $annotations[] = "before $end"; |
| 691 | + $annotations[] = "before {$this->end->text()}"; |
692 | 692 | } |
693 | 693 | |
694 | 694 | $this->where = $where; |
— | — | @@ -756,25 +756,23 @@ |
757 | 757 | |
758 | 758 | $one_month = '100000000'; |
759 | 759 | 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(); |
761 | 762 | |
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(); |
764 | 765 | |
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 | + |
769 | 775 | } |
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) )); |
777 | 776 | |
778 | | - |
779 | 777 | $this->output->addHTML(<<<HTML |
780 | 778 | <form id="lqt_archive_search_form" action="{$this->title->getLocalURL()}"> |
781 | 779 | <input type="hidden" name="lqt_show_archive" value="1"> |
Index: branches/liquidthreads/extensions/LqtModel.php |
— | — | @@ -20,16 +20,39 @@ |
21 | 21 | $this->second = intval( substr( $text, 12, 2 ) ); |
22 | 22 | } |
23 | 23 | function lastMonth() { |
24 | | - $d = clone $this; |
25 | | - $d->month -= 1; |
26 | | - return $d; |
| 24 | + return $this->moved('-1 month'); |
27 | 25 | } |
| 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 | + } |
28 | 34 | /* function monthString() { |
29 | 35 | return sprintf( '%04d%02d', $this->year, $this->month ); |
30 | 36 | }*/ |
31 | 37 | static function monthString($text) { |
32 | 38 | return substr($text, 0, 6); |
33 | 39 | } |
| 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 | + } |
34 | 57 | static function beginningOfMonth($yyyymm) { return $yyyymm . '00000000'; } |
35 | 58 | static function endOfMonth($yyyymm) { return $yyyymm . '31235959'; } |
36 | 59 | function text() { |
— | — | @@ -40,9 +63,7 @@ |
41 | 64 | return new Date(wfTimestampNow()); |
42 | 65 | } |
43 | 66 | 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"); |
47 | 68 | } |
48 | 69 | function midnight() { |
49 | 70 | $d = clone $this; |