* 機能 [#oc2df072]
指定した日付までの日数を表示します。
自作プラグイン作成の練習を兼ねてます。
* 使い方 [#n71ae85c]
#pre{{
短答試験まであと &date_counter("2008-05-18"); 日。
短答試験まであと &date_counter("2010-05-23"); 日。
}}
* 結果 [#e440b705]
短答試験まであと &date_counter("2008-05-18"); 日。
短答試験まであと &date_counter("2010-05-23"); 日。
* ソースコード [#we029f0b]
&ref(date_counter.inc.php.tgz); : ver. 0.1, 2008/04/08
#code(php,nonumber){{
<?php
/////////////////////////////////////////////////
// PukiWiki - Yet another WikiWikiWeb clone.
//
// &date_counter(target_date);
//
// (darget_date - now) の日数を返す。
//
// 日付は target_date 引数に "YYYY-MM-DD" の形式で書く。
function plugin_date_counter_inline()
{
if (func_num_args()) {
$argv = func_get_args();
$date_str = $argv[0];
}
// YYYY-MM-DD
$year = substr($date_str, 0, 4);
$month = substr($date_str, 5, 2);
$day = substr($date_str, 8, 2);
if (checkdate($month, $day, $year)) {
$target_date = mktime(0, 0, 0, $month, $day, $year);
$today = mktime();
$count = ceil(($target_date - $today) / (60 * 60 * 24));
return $count;
}
}
?>
}}
* 注意点 [#i56d2890]
- 入力チェックがありません。
* 著作権表示 [#d7104b33]
Copyright (C) 2008 SUGIMURA Takashi, all rights reserved.
(誰も使う人はいないでしょうがライセンスはまた別途考えます)
----
#comment