#!/usr/bin/ruby

require 'time'

class Timestamp
  attr_accessor :sec, :usec
  def initialize(ts)
    ts = ts.to_f if ts.is_a? String
    @sec = ts.truncate
    @usec = ((ts - @sec) * 1000000).round
  end
  def to_i
    return (@sec << 32) + @usec
  end
end

s = ARGV[0]

if s =~ /^(\d+)(\.\d+)?$/
  if $1.length <= 10
    # if ts is in the format sec.usec then sec can't be more
    # than 10 digits (2^32)
    puts Time.at(s.to_f).to_s
  else
    # so ts is a 64 bit number: 32bit for sec and 32 for usec
    ts = s.to_i
    sec = ts >> 32
    usec = ts & 0xFFFFFFFF
    puts Time.at(sec, usec).to_s
  end
else
  t = Time.parse(s)
  puts t.to_f.to_s
  ts = Timestamp.new(t.to_i)
  puts t.to_i.to_s
end

