User Tools

Site Tools


Sidebar


Site Information


Interactive Maps

Sidebar

scode:perl:moraff

Moraff Mahjongg / Time

Converting .Net Ticks to Epoch

I've got Moraff's Mahjongg XIV International (sorry, but seriously, Roman numerals for a Chinese game?). There are numerous issues with their code, one of which is granting awards. So I figured-out what programming software and database they were using so I could fix their accounting issues!

They use .Net. I use Perl. We aren't exactly what ya call "compatible." Where there's a will, there's code!

Perl Source Code

#!/usr/bin/perl -w
use strict;
use Time::localtime;
my $tm;
 
# Moraff Mahjongg uses a SQLite database, but stores time info as .Net values.
# I use Perl.
# What we have here is, failure to communicate!
 
my $iMicroSecs;     # elapsed time from game, microseconds
my $iETSecs;        # elapsed time in whole seconds
my $tmSecs;         # "time" seconds, human
my $tmMins;         # "time" minutes, human
my $iFACTOR = 10000000;
my $iEpochTicks = 621355968000000000;    # Change Ticks to Unix epoch!
 
################
# ELAPSED TIME #
################
 
#$iMicroSecs = 4710000000;   # 7:51
$iMicroSecs = 1590000000;   # 2:39
 
$iETSecs = $iMicroSecs / $iFACTOR;
$tmSecs = $iETSecs % 60;
$tmMins = ($iETSecs - $tmSecs) / 60;
printf "Elapsed Time: %02d:%02d\n\n", $tmMins, $tmSecs;
 
#############
# DATE/TIME #
#############
 
## If you subtract $iEpochTicks from Ticks, you should be able to convert to perl time!
# EDT time zone: Saturday, July 22, 2017 10:12:35 PM (see below in __END__)
my $tmDate1 = 636363727554730800 - $iEpochTicks;
$tmDate1 = $tmDate1 / $iFACTOR;     # convert from Ticks (.Net microseconds) to epoch seconds, as float
print "\$tmDate1 (float): $tmDate1\n";
 
$tm = localtime($tmDate1);  # get as LOCAL time zone (e.g. EDT)!!!
my $sYr = $tm->year + 1900;
my $sMon = sprintf "%02d", $tm->mon + 1;
my $sDay = sprintf "%02d", $tm->mday;
my $sHH = sprintf "%02d", $tm->hour;
my $sMM = sprintf "%02d", $tm->min;
print "$sMon-$sDay-$sYr @ $sHH:$sMM\n\n";
 
my $tmDate2 = 636363727554730800 - $iEpochTicks;
$tmDate2 = int($tmDate2 / $iFACTOR);    # convert from Ticks (.Net microseconds) to epoch seconds, as int
print "\$tmDate2 (int): $tmDate2\n";
 
$tm = localtime($tmDate2);
$sYr = $tm->year + 1900;
$sMon = sprintf "%02d", $tm->mon + 1;
$sDay = sprintf "%02d", $tm->mday;
$sHH = sprintf "%02d", $tm->hour;
$sMM = sprintf "%02d", $tm->min;
print "$sMon-$sDay-$sYr @ $sHH:$sMM\n";
 
1;
 
__END__
 
Datetime:
* 2017-07-23 at 02:12:35 GMT
* Saturday, July 22, 2017 10:12:35 PM EDT
* 636363727554730800
 
A ticks value of 31241376000000000 represents the date:
Friday, January 01, 0100 12:00:00 midnight.
 
##############
# REFERENCES #
##############
 
Ticks: https://www.nntp.perl.org/group/perl.datetime/2003/11/msg4684.html
Convert Ticks: http://tickstodatetime.com/
Convert Epoch: https://www.epochconverter.com/
scode/perl/moraff.txt · Last modified: 2017/08/27 07:33 by terrill