Skip to content

Instantly share code, notes, and snippets.

@soh335
Created November 26, 2011 06:15
Show Gist options
  • Save soh335/1395153 to your computer and use it in GitHub Desktop.
Save soh335/1395153 to your computer and use it in GitHub Desktop.
x0y240t342v1n3
-----------
35.310059 ~ 35.321045
139.482422 ~ 139.504395
2010-12-31T23:59:10 ~ 2011-01-01T00:16:14
x0y240t342v1
-----------
35.288086 ~ 35.332031
139.482422 ~ 139.570312
2010-12-31T21:59:42 ~ 2011-01-01T00:16:14
use strict;
use warnings;
use lib qw/lib/;
use Data::Wheren::7Bit;
use DateTime;
use feature qw/say/;
my %zone = ( time_zone => "Asia/Tokyo" );
my $base_time = DateTime->new(
year => 2011,
month => 1,
day => 1,
%zone
);
my $wheren = Data::Wheren::7Bit->new();
my $str = $wheren->encode(35.3137, 139.4863, $base_time->epoch, 7);
say $str;
debug_data($wheren->decode_to_interval($str), 1);
$str = substr($str, 0, -2);
print "\n\n";
say $str;
debug_data($wheren->decode_to_interval($str), 1);
sub debug_data {
my ($res, $convert_datetime) = @_;
say "-----------";
say sprintf "%f ~ %f", $res->[0][0], $res->[0][1];
say sprintf "%f ~ %f", $res->[1][0], $res->[1][1];
if ( $convert_datetime ) {
say sprintf "%s ~ %s", DateTime->from_epoch( epoch => $res->[2][0], %zone), DateTime->from_epoch( epoch => $res->[2][1], %zone);
}
else {
say sprintf "%s ~ %s", $res->[2][0], $res->[2][1];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment