#!/usr/bin/ruby
require 'date'

unless (ARGV.length == 1)
  puts("A single filename argument is required")
  exit(1)
end

imgfile  = ARGV[0]
unless (File.file?(imgfile))
  puts("#{imgfile} not found")
  exit(1)
end

basefile = File.basename(imgfile, ".tiff")

# Attempt to extract YYMMDD-HHMMSS from the file name.
# If a match is found extract and emit the timestamp and return.
# Otherwise emit "Unknown DATE/TIM"
begin
  date = DateTime.strptime(basefile[-13..], "%y%m%d-%H%M%S")
  result = date.strftime("%d %b %Y  %H:%M:%S")
  puts(result)
rescue
  puts("Unknown DATE/TIME")
end
