関数 get_weekstartend()
2014/11/25
定義ファイル :/blog/wp-includes/functions.php 2
get_weekstartend()
MySQLのdatetime値から、週の始まりと終わりを取得する
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | /** * Get the week start and end from the datetime or date string from MySQL. * * @since 0.71 * * @param string $mysqlstring Date or datetime field type from MySQL. * @param int|string $start_of_week Optional. Start of the week as an integer. Default empty string. * @return array Keys are 'start' and 'end'. */ function get_weekstartend( $mysqlstring, $start_of_week = '' ) { // MySQL string year. $my = substr( $mysqlstring, 0, 4 ); // MySQL string month. $mm = substr( $mysqlstring, 8, 2 ); // MySQL string day. $md = substr( $mysqlstring, 5, 2 ); // The timestamp for MySQL string day. $day = mktime( 0, 0, 0, $md, $mm, $my ); // The day of the week from the timestamp. $weekday = date( 'w', $day ); if ( !is_numeric($start_of_week) ) $start_of_week = get_option( 'start_of_week' ); if ( $weekday < $start_of_week ) $weekday += 7; // The most recent week start day on or before $day. $start = $day - DAY_IN_SECONDS * ( $weekday - $start_of_week ); // $start + 7 days - 1 second. $end = $start + 7 * DAY_IN_SECONDS - 1; return compact( 'start', 'end' ); } |
関数
substr() 文字列の一部分を返す
mktime() 日付を Unix のタイムスタンプとして取得する
date() ローカルの日付/時刻を書式化する
is_numeric() 変数が数字または数値形式の文字列であるかを調べる
get_option() optionsデータベーステーブルから、指定したオプションの値を取得する
compact() 変数名とその値から配列を作成する
定数
DAY_IN_SECONDS 24時間を秒であらわす 24*3600=86400
定義された場所
wp_initial_constants()