| 26 | | |
| 27 | | # regex to match wc3dtf |
| 28 | | $pat = "/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(:(\d{2}))?(?:([-+])(\d{2}):?(\d{2})|(Z))?/"; |
| 29 | | |
| 30 | | if ( preg_match( $pat, $date_str, $match ) ) { |
| 31 | | list( $year, $month, $day, $hours, $minutes, $seconds) = |
| 32 | | array( $match[1], $match[2], $match[3], $match[4], $match[5], $match[6]); |
| 33 | | |
| 34 | | # calc epoch for current date assuming GMT |
| 35 | | $epoch = gmmktime( $hours, $minutes, $seconds, $month, $day, $year); |
| 36 | | |
| 37 | | $offset = 0; |
| 38 | | if ( $match[10] == 'Z' ) { |
| 39 | | # zulu time, aka GMT |
| 40 | | } |
| 41 | | else { |
| 42 | | list( $tz_mod, $tz_hour, $tz_min ) = |
| 43 | | array( $match[8], $match[9], $match[10]); |
| 44 | | |
| 45 | | # zero out the variables |
| 46 | | if ( ! $tz_hour ) { $tz_hour = 0; } |
| 47 | | if ( ! $tz_min ) { $tz_min = 0; } |
| 48 | | |
| 49 | | $offset_secs = (($tz_hour*60)+$tz_min)*60; |
| 50 | | |
| 51 | | # is timezone ahead of GMT? then subtract offset |
| 52 | | # |
| 53 | | if ( $tz_mod == '+' ) { |
| 54 | | $offset_secs = $offset_secs * -1; |
| 55 | | } |
| 56 | | |
| 57 | | $offset = $offset_secs; |
| 58 | | } |
| 59 | | $epoch = $epoch + $offset; |
| 60 | | return $epoch; |
| 61 | | } |
| 62 | | else { |
| 63 | | return -1; |
| 64 | | } |
| | 26 | |
| | 27 | # regex to match wc3dtf |
| | 28 | $pat = "/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(:(\d{2}))?(?:([-+])(\d{2}):?(\d{2})|(Z))?/"; |
| | 29 | |
| | 30 | if ( preg_match( $pat, $date_str, $match ) ) { |
| | 31 | list( $year, $month, $day, $hours, $minutes, $seconds) = |
| | 32 | array( $match[1], $match[2], $match[3], $match[4], $match[5], $match[6]); |
| | 33 | |
| | 34 | # calc epoch for current date assuming GMT |
| | 35 | $epoch = gmmktime( $hours, $minutes, $seconds, $month, $day, $year); |
| | 36 | |
| | 37 | $offset = 0; |
| | 38 | if ( $match[10] == 'Z' ) { |
| | 39 | # zulu time, aka GMT |
| | 40 | } |
| | 41 | else { |
| | 42 | list( $tz_mod, $tz_hour, $tz_min ) = |
| | 43 | array( $match[8], $match[9], $match[10]); |
| | 44 | |
| | 45 | # zero out the variables |
| | 46 | if ( ! $tz_hour ) { $tz_hour = 0; } |
| | 47 | if ( ! $tz_min ) { $tz_min = 0; } |
| | 48 | |
| | 49 | $offset_secs = (($tz_hour*60)+$tz_min)*60; |
| | 50 | |
| | 51 | # is timezone ahead of GMT? then subtract offset |
| | 52 | # |
| | 53 | if ( $tz_mod == '+' ) { |
| | 54 | $offset_secs = $offset_secs * -1; |
| | 55 | } |
| | 56 | |
| | 57 | $offset = $offset_secs; |
| | 58 | } |
| | 59 | $epoch = $epoch + $offset; |
| | 60 | return $epoch; |
| | 61 | } |
| | 62 | else { |
| | 63 | return -1; |
| | 64 | } |