Ignore:
Timestamp:
2012/01/17 16:32:25 (12 years ago)
Author:
Seasoft
Message:

2.12系へマイルストーン変更となったチケット分を差し戻し
r21326 #1536
r21325 #1528
r21324 #1547,#1546
r21323 #1546
r21322 #1543
r21321 #1536
r21320 #1536
r21319 #1544
r21318 #1521,#1522
r21317 #1431

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_11-dev/data/module/SOAP/Type/duration.php

    r21318 r21410  
    11<?php 
    2 /** 
    3  * This file contains the code for the SOAP_Type_duration class. 
    4  * 
    5  * PHP versions 4 and 5 
    6  * 
    7  * LICENSE: This source file is subject to version 2.02 of the PHP license, 
    8  * that is bundled with this package in the file LICENSE, and is available at 
    9  * through the world-wide-web at http://www.php.net/license/2_02.txt.  If you 
    10  * did not receive a copy of the PHP license and are unable to obtain it 
    11  * through the world-wide-web, please send a note to license@php.net so we can 
    12  * mail you a copy immediately. 
    13  * 
    14  * @category   Web Services 
    15  * @package    SOAP 
    16  * @author     Shane Caraveo <Shane@Caraveo.com>   Port to PEAR and more 
    17  * @author     Jan Schneider <jan@horde.org>       Maintenance 
    18  * @copyright  2003-2007 The PHP Group 
    19  * @license    http://www.php.net/license/2_02.txt  PHP License 2.02 
    20  * @link       http://pear.php.net/package/SOAP 
    21  */ 
     2/* 
     3http://www.w3.org/TR/xmlschema-2/ 
    224 
    23 /** 
    24  * This is only an aproximation of duration, more work still to do.  See the 
    25  * schema url for more info on duration. 
    26  * 
    27  * http://www.w3.org/TR/xmlschema-2/ 
    28  * 
    29  * [Definition:]   duration represents a duration of time. The value space of 
    30  * duration is a six-dimensional space where the coordinates designate the 
    31  * Gregorian year, month, day, hour, minute, and second components 
    32  * defined in  5.5.3.2 of [ISO 8601], respectively. These components are 
    33  * ordered in their significance by their order of appearance i.e. as year, 
    34  * month, day, hour, minute, and second. 
    35  * 
    36  * 3.2.6.1 Lexical representation 
    37  * The lexical representation for duration is the [ISO 8601] extended 
    38  * format PnYn MnDTnH nMnS, where nY represents the number of 
    39  * years, nM the number of months, nD the number of days, 'T' is the 
    40  * date/time separator, nH the number of hours, nM the number of 
    41  * minutes and nS the number of seconds. The number of seconds 
    42  * can include decimal digits to arbitrary precision. 
    43  * 
    44  * The values of the Year, Month, Day, Hour and Minutes components 
    45  * are not restricted but allow an arbitrary integer. Similarly, the 
    46  * value of the Seconds component allows an arbitrary decimal. 
    47  * Thus, the lexical representation of duration does not follow the 
    48  * alternative format of  5.5.3.2.1 of [ISO 8601]. 
    49  * 
    50  * An optional preceding minus sign ('-') is allowed, to indicate a 
    51  * negative duration. If the sign is omitted a positive duration is 
    52  * indicated. See also ISO 8601 Date and Time Formats (D). 
    53  * 
    54  * For example, to indicate a duration of 1 year, 2 months, 3 days, 
    55  * 10 hours, and 30 minutes, one would write: P1Y2M3DT10H30M. 
    56  * One could also indicate a duration of minus 120 days as: -P120D. 
    57  * 
    58  * Reduced precision and truncated representations of this format 
    59  * are allowed provided they conform to the following: 
    60  * 
    61  * If the number of years, months, days, hours, minutes, or seconds 
    62  * in any expression equals zero, the number and its corresponding 
    63  * designator *may* be omitted. However, at least one number and 
    64  * its designator *must* be present. 
    65  * The seconds part *may* have a decimal fraction. 
    66  * The designator 'T' shall be absent if all of the time items are absent. 
    67  * The designator 'P' must always be present. 
    68  * For example, P1347Y, P1347M and P1Y2MT2H are all allowed; P0Y1347M 
    69  * and P0Y1347M0D are allowed. P-1347M is not allowed although -P1347M 
    70  * is allowed. P1Y2MT is not allowed. 
    71  * 
    72  * @access   public 
    73  * @package  SOAP 
    74  * @author   Shane Caraveo <shane@php.net> Port to PEAR and more 
    75  * @author   Jan Schneider <jan@horde.org> Maintenance 
    76  * @todo     Figure out best aproximation for year and month conversion to 
    77  *           seconds 
    78  */ 
     5[Definition:]   duration represents a duration of time. The value space of 
     6duration is a six-dimensional space where the coordinates designate the 
     7Gregorian year, month, day, hour, minute, and second components 
     8defined in  5.5.3.2 of [ISO 8601], respectively. These components are 
     9ordered in their significance by their order of appearance i.e. as year, 
     10month, day, hour, minute, and second.  
     11 
     123.2.6.1 Lexical representation 
     13The lexical representation for duration is the [ISO 8601] extended 
     14format PnYn MnDTnH nMnS, where nY represents the number of 
     15years, nM the number of months, nD the number of days, 'T' is the 
     16date/time separator, nH the number of hours, nM the number of 
     17minutes and nS the number of seconds. The number of seconds 
     18can include decimal digits to arbitrary precision. 
     19 
     20The values of the Year, Month, Day, Hour and Minutes components 
     21are not restricted but allow an arbitrary integer. Similarly, the 
     22value of the Seconds component allows an arbitrary decimal. 
     23Thus, the lexical representation of duration does not follow the 
     24alternative format of  5.5.3.2.1 of [ISO 8601]. 
     25 
     26An optional preceding minus sign ('-') is allowed, to indicate a 
     27negative duration. If the sign is omitted a positive duration is 
     28indicated. See also ISO 8601 Date and Time Formats (D).  
     29 
     30For example, to indicate a duration of 1 year, 2 months, 3 days, 
     3110 hours, and 30 minutes, one would write: P1Y2M3DT10H30M. 
     32One could also indicate a duration of minus 120 days as: -P120D.  
     33 
     34Reduced precision and truncated representations of this format 
     35are allowed provided they conform to the following:  
     36 
     37If the number of years, months, days, hours, minutes, or seconds 
     38in any expression equals zero, the number and its corresponding 
     39designator *may* be omitted. However, at least one number and 
     40its designator *must* be present.  
     41The seconds part *may* have a decimal fraction.  
     42The designator 'T' shall be absent if all of the time items are absent. 
     43The designator 'P' must always be present.  
     44For example, P1347Y, P1347M and P1Y2MT2H are all allowed; P0Y1347M 
     45and P0Y1347M0D are allowed. P-1347M is not allowed although -P1347M 
     46is allowed. P1Y2MT is not allowed.  
     47 
     48*/ 
     49 
     50/* this is only an aproximation of duration, more work still to do. 
     51   see above schema url for more info on duration 
     52    
     53   TODO: figure out best aproximation for year and month conversion to seconds 
     54*/ 
     55    
     56$ereg_duration = '(-)?P([0-9]+Y)?([0-9]+M)?([0-9]+D)?T?([0-9]+H)?([0-9]+M)?([0-9]+S)?'; 
    7957class SOAP_Type_duration 
    8058{ 
    8159    // format PnYnMnDTnHnMnS 
    82     function unix_to_duration($seconds) 
    83     { 
     60    function unix_to_duration($seconds) { 
    8461        return SOAP_Type_duration::getduration($seconds); 
    8562    } 
    86  
    87     function mod($a, $b, &$d, &$r) 
    88     { 
    89         $d = floor($a / $b); 
     63     
     64    function mod($a, $b, &$d, &$r) { 
     65        $d = floor( $a / $b ); 
    9066        $r = $a % $b; 
    9167    } 
    92  
    93     function getduration($seconds) 
    94     { 
     68     
     69    function getduration($seconds) { 
    9570        $neg = ''; 
    9671        if ($seconds < 0) { 
     
    9873            $seconds = $seconds * -1; 
    9974        } 
    100  
     75         
    10176        $_mi = 60; 
    10277        $_h = $_mi * 60; 
     
    11186        SOAP_Type_duration::mod($seconds, $_h, $h, $seconds); 
    11287        SOAP_Type_duration::mod($seconds, $_mi, $mi, $s); 
    113  
     88         
    11489        $duration = $neg.'P'; 
    11590        if ($y) $duration .= $y.'Y'; 
     
    12196        if ($s) $duration .= $s.'S'; 
    12297        if ($duration == 'P' || $duration == '-P') $duration = 'PT0S'; 
    123  
    12498        return $duration; 
    12599    } 
    126  
    127     function mkduration($n, $Y, $Mo, $D, $H, $Mi, $S) 
    128     { 
     100     
     101    function mkduration($n, $Y, $Mo, $D, $H, $Mi, $S) { 
    129102        $_mi = 60; 
    130103        $_h = $_mi * 60; 
     
    133106        $_m = $_d * 30; 
    134107        $_y = $_d * 365; 
    135  
     108         
    136109        $sec = $Y * $_y + $Mo * $_m + $D * $_d + $H * $_h + $Mi * $_mi + $S; 
    137110        if ($n == '-') $sec = $sec * -1; 
    138  
    139111        return $sec; 
    140112    } 
    141  
    142     function duration_to_unix($duration) 
    143     { 
    144         if (ereg('(-)?P([0-9]+Y)?([0-9]+M)?([0-9]+D)?T?([0-9]+H)?([0-9]+M)?([0-9]+S)?', $duration, $regs)) { 
     113     
     114    function duration_to_unix($duration) { 
     115        global $ereg_duration; 
     116        if (ereg($ereg_duration,$duration,$regs)) { 
    145117            return SOAP_Type_duration::mkduration($regs[1], $regs[2], $regs[3], $regs[4], $regs[5], $regs[6], $regs[7]); 
    146118        } 
    147         return false; 
     119        return FALSE; 
    148120    } 
    149  
    150     function is_duration($duration) 
    151     { 
    152         return ereg('(-)?P([0-9]+Y)?([0-9]+M)?([0-9]+D)?T?([0-9]+H)?([0-9]+M)?([0-9]+S)?', $duration, $regs); 
     121     
     122    function is_duration($duration) { 
     123        global $ereg_duration; 
     124        return ereg($ereg_duration,$duration,$regs); 
    153125    } 
    154  
    155     function _test($time) 
    156     { 
     126     
     127    function _test($time) { 
    157128        if (SOAP_Type_duration::is_duration($time)) { 
    158129            $t = SOAP_Type_duration::duration_to_unix($time); 
     
    164135        return $t; 
    165136    } 
    166  
    167     function add($d1, $d2) 
    168     { 
     137     
     138    function add($d1, $d2) { 
    169139        $s1 = SOAP_Type_duration::duration_to_unix($d1); 
    170140        $s2 = SOAP_Type_duration::duration_to_unix($d2); 
    171141        return SOAP_Type_duration::unix_to_duration($s1 + $s2); 
    172142    } 
    173  
    174     function subtract($d1, $d2) 
    175     { 
     143     
     144    function subtract($d1, $d2) { 
    176145        $s1 = SOAP_Type_duration::duration_to_unix($d1); 
    177146        $s2 = SOAP_Type_duration::duration_to_unix($d2); 
     
    181150} 
    182151 
    183 /* Tests. */ 
     152/* tests */ 
     153 
    184154$t = SOAP_Type_duration::_test('P1Y2M3DT10H30M'); 
    185155SOAP_Type_duration::_test($t); 
     
    187157SOAP_Type_duration::_test($t); 
    188158 
    189 /* Duration since 1970. */ 
     159// duration since 1970 
    190160$t = SOAP_Type_duration::_test(time()); 
    191161SOAP_Type_duration::_test($t); 
    192162 
    193 echo 'Add should be PT0S: ' . SOAP_Type_duration::add('-P120D','P4M') . "\n"; 
    194 echo 'Subtract should be PT0S: ' . SOAP_Type_duration::subtract('P120D','P4M') . "\n"; 
     163print "Add should be PT0S: ".SOAP_Type_duration::add('-P120D','P4M')."\n"; 
     164print "Subtract should be PT0S: ".SOAP_Type_duration::subtract('P120D','P4M')."\n"; 
     165?> 
Note: See TracChangeset for help on using the changeset viewer.