/dev/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/dev/trunk

« back to all changes in this revision

Viewing changes to classes/time/msticks.php

  • Committer: Suren A. Chilingaryan
  • Date: 2008-04-02 10:23:22 UTC
  • Revision ID: csa@dside.dyndns.org-20080402102322-okib92sicg2dx3o3
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
 
 
4
 
 
5
/* DS: Rewrite with bcmath for 32bit system compatibility */
 
6
class MSTICKS {
 
7
 var $reader;
 
8
 var $correction;
 
9
 
 
10
 const START = 621355968000000000;
 
11
    
 
12
 function __construct(&$reader, $correction = 0) {
 
13
    $this->reader = &$reader;
 
14
    if (is_int($correction)) $this->correction = $correction;
 
15
    else $this->correction = 0;
 
16
 }
 
17
    
 
18
 function ImportTime($dt) {
 
19
    return (int)floor(10000000*$dt->format("U.u")) + MSTICKS::START - $this->correction;
 
20
 }
 
21
    
 
22
 function ExportTime($db_time) {
 
23
    global $adei_profiler;
 
24
 
 
25
    $ticks = ($db_time - MSTICKS::START + $this->correction);
 
26
 
 
27
    $ns100 = $ticks % 10000000;
 
28
    $timestamp =  ($ticks - $ns100) / 10000000;
 
29
        
 
30
    if ($ns100) {
 
31
        $len = strlen($ns100);
 
32
        if ($len < 7) $ns100 = str_repeat('0', 7 - $len) . $ns100;
 
33
 
 
34
        return new DateTime(strftime("%Y/%m/%d %H:%M:%S", $timestamp) . ".$ns100", $this->reader->gmt_timezone);
 
35
    } else {
 
36
        return new DateTime("@$timestamp", $this->reader->gmt_timezone);
 
37
    }
 
38
 }
 
39
}
 
40
 
 
41
?>
 
 
b'\\ No newline at end of file'