Since I am INSANELY hyped for the Final Fantasy XV Uncovered event, I want you to write me a program to tell me when it is!!!

The input

Your take input in the form of HH:MM XDT, where HH is a number in the range 1-12, MM is a number between 0-60, and XDT is a time zone, with X being one of E (eastern, UTC-4), C (central, UTC-5), P (pacific, UTC-7), or M (mountain, UTC-6). This is a time assumed to be PM. Valid inputs include:

1:00 EDT (1 PM Eastern Daylight Time)
4:05 MDT (4:05 PM Mountain Daylight Time)
12:23 PDT (12:23 PM Pacific Daylight Time)
1:10 CDT (1:10 PM Central Daylight Time)

The input may be assumed to be valid.

The output

Your program must do the following:

  1. Convert the given time to PDT and output It is XX:XX PM PDT., where XX:XX is the converted time. Note that you do not need to handle any case where converting the time would cross the AM/PM boundary.

  2. Print one of the following:

    1. If the converted time is before 6:00 PM PDT, print X minutes until the pre-show!, replacing X with the number of minutes until 6:00 PM PDT.

    2. If the converted time is after or equal to 6:00 PM PDT and before 7:00 PM PDT, print Pre-show started X minutes ago; UNCOVERED is starting in Y minutes!, where X is the number of minutes that have passed since 6:00 PM PDT, and Y is the number of minutes until 7:00 PM PDT.

    3. If the converted time is after or equal to 7:00 PM PDT, print UNCOVERED started X minutes ago!, where X is the number of minutes that have passed since 7:00 PM PDT.

Each string printed must be followed by a newline.


This is code golf, so the shortest program wins.

  • \$\begingroup\$ Are all inputs assumed to be valid? \$\endgroup\$
    – Leaky Nun
    Mar 31, 2016 at 2:40
  • 1
    \$\begingroup\$ Is HH:MM XDT a typo? It can be CST. \$\endgroup\$
    – Leaky Nun
    Mar 31, 2016 at 2:42
  • 1
    \$\begingroup\$ Would 2:45 EDT appear so we need to detect whether the converted time is PM or AM? \$\endgroup\$
    – Leaky Nun
    Mar 31, 2016 at 2:45
  • \$\begingroup\$ It would have been nice if you'd actually included the UTC offsets of the four time zones so I didn't have to look them up myself. \$\endgroup\$
    – Neil
    Mar 31, 2016 at 8:26
  • \$\begingroup\$ @KennyLau The CST was a typo, and no time would appear that could cross the AM/PM boundary. Edited the post. \$\endgroup\$ Mar 31, 2016 at 15:14

6 Answers 6


Python (335 bytes)

t=raw_input().replace(*': ').split();x='PMCE'.index(t[2][0]);t[0]=int(t[0])+x;print '%s:%s PM PDT' % tuple(t[:1]);x=t[0]*60+int(t[1]);print ['%s minutes until the pre-show!'%(360-x),'Pre-show started %s minutes ago; UNCOVERED is starting in %s minutes!'%((x-360),(420-x)), 'UNCOVERED started %s minutes ago!'%(x-420)][(x>360)+(x>420)]


1:00 MDT
2:00 PM PDT
240 minutes until the pre-show!

6:00 CDT  
8:00 PM PDT
UNCOVERED started 60 minutes ago!

6:50 PDT
6:50 PM PDT
Pre-show started 50 minutes ago; UNCOVERED is starting in 10 minutes!
  • \$\begingroup\$ Welcome to PPCG! Hope you'll have a great time here. \$\endgroup\$
    – Leaky Nun
    Mar 31, 2016 at 6:59
  • \$\begingroup\$ Here is an untested golfed version which is 340 bytes: t=raw_input().replace(' ',':').split(':');x='PMCE'.index(t[2][0]);t[0]=int(t[0])+x;t[2]='PDT';print'%s:%s PM %s'%tuple(t);x=t[0]*60+int(t[1]);print['%s minutes until the pre-show!'%(360-x),'Pre-show started %s minutes ago; UNCOVERED is starting in %s minutes!'%((x-360),(420-x)),'UNCOVERED started %s minutes ago!'%(x-420)][(x>360)+(x>420)] \$\endgroup\$
    – Leaky Nun
    Mar 31, 2016 at 7:01
  • \$\begingroup\$ Welcome to PPCG, we hope you'll find what you want here and will enjoy your time with us! If you have the time and will, don't forget to put an ungolfed version of your code (maybe with comments?), that will greatly help people understand your code, and help them provide you tips for golfing it even more ;). \$\endgroup\$
    – Katenkyo
    Mar 31, 2016 at 7:07
  • \$\begingroup\$ You can replace .replace(' ', ':').split(':') with .replace(*': ').split(), saving 6 bytes \$\endgroup\$
    – Blue
    Mar 31, 2016 at 11:46
  • \$\begingroup\$ We're even! \$\endgroup\$
    – Leaky Nun
    Mar 31, 2016 at 15:21

Lua, 357 335 332 bytes

Thanks to @Katenkyo for chopping off 22 bytes.


h,m,t=(...):match("(%d+):(%d+) (.)")f=tonumber h=(f(h)-("PMCE"):find(t))%12+1m=f(m)print("It is "..h..":"..m.." PM PDT.")a=" minutes"b="UNCOVERED"n=(6-h)*60-m r=h<6 and n..a.." until the pre-show!"or h<7 and"Pre-show started "..m..a.." ago; "..b.." is starting in "..(n+60)..a.."!"or b.." started "..(m+(h-7)*60)..a.." ago!"print(r)

(Try it online)


n = "7:10 CST"

h,m,t = n:match("(%d+):(%d+) (.)")
h = (tonumber(h) - ("PMCE"):find(t))%12 + 1
m = tonumber(m)
print("It is "..h..":"..m.." PM PDT.")

n = (6-h)*60-m

if h<6 then
  r=n.." minutes until the pre-show!"
elseif h<7 then
  r="Pre-show started "..m.." minutes ago; UNCOVERED is starting in "..(n+60).." minutes!"
  r="UNCOVERED started "..(m+(h-7)*60).." minutes ago!"

  • \$\begingroup\$ You never have to use tonumber when your number isn't in an other base than 10, instead, you can write h=h+0, the addition of 0 will automatically convert the result to a number. Also, is n=(...) mandatory? wouldn't it better to inline the use of ... as following -> h,m,t=(...):match("(%d+):(%d+) (.)"), you won't reuse it anyway, as you then change the value of n using h and m :) \$\endgroup\$
    – Katenkyo
    Mar 31, 2016 at 6:17
  • \$\begingroup\$ Also, you should be able to change you if/elseif/else for a single ternary statement of the form r=(h<6 and n.." minutes until the pre-show!" )or h<7 and "Pre-show started "..m.." minutes ago; UNCOVERED is starting in "..(n+60).." minutes!" or "UNCOVERED started "..(m+(h-7)*60).." minutes ago!". It might have to be reworked a little, but using this will save a lot of byte. For information, the structure of a ternary in lua is <condition> and <case true, have to be evaluated to true> or <case false, can be anything> \$\endgroup\$
    – Katenkyo
    Mar 31, 2016 at 6:23
  • \$\begingroup\$ (still didn't have the space to finish what I wanted to say) Don't forget to check the tips for lua, they aren't exhaustive yet, but there's some little useful things :) \$\endgroup\$
    – Katenkyo
    Mar 31, 2016 at 6:25
  • \$\begingroup\$ Here's a not-tested golfed solution if you want a base to include all that h,m,t=(...):match("(%d+):(%d+) (.)")h=(h-("PMCE"):find(t))%12+1m=m+0print("It is "..h..":"..m.." PM PDT.")a=" minutes"b="UNCOVERED"n=(6-h)*60-m r=(h<6 and n.." minutes until the pre-show!" )or h<7 and"Pre-show started "..m..a.." ago; "..b.." is starting in "..(n+60)..a.."!"or b.." started "..(m+(h-7)*60)..a.." ago!"end print(r) It's actually 329 bytes ;). \$\endgroup\$
    – Katenkyo
    Mar 31, 2016 at 6:57
  • \$\begingroup\$ I've updated it. 0+m does not work here. \$\endgroup\$
    – Leaky Nun
    Mar 31, 2016 at 6:58

JavaScript (ES6), 257 bytes

s=>(t=` minutes`,a=s.match(/(\d+):(\d+) (.)/),h=+a[1]+"PMCE".search(a[3]),m=420-h*60-a[2],`It is ${h}:${a[2]} PM PDT
${h<6?m-60+t+` until the pre-show`:h<7?`Pre-show started ${60-m+t} ago; UNCOVERED is starting in ${m+t}`:`UNCOVERED started ${-m+t} ago`}!`)
  • \$\begingroup\$ Don't know the savings but there are a few string there that are repeated you could golf more with. "re-show" and "UNCOVERED" for example. \$\endgroup\$
    – Matt
    Apr 1, 2016 at 4:54
  • \$\begingroup\$ @Matt For a string that is only repeated once the overhead is 13 bytes so it would need to be 14 bytes long to be worth it. "minutes" got a bonus for being next to the time and being needed four times. \$\endgroup\$
    – Neil
    Apr 1, 2016 at 7:53

C, 333 bytes

#define p printf
char s[9];main(t){gets(s);s[5]=0;s[1]-=2+s[6]%2-s[6]%3;s[1]<48&&(s[1]+=10,--*s);
t=*s*600+s[1]*60+s[3]*10+s[4]-32568;p("It is %s PM PDT.",s);
t<0?p("%d minutes until the pre-show!",-t):t<60?p(
"Pre-show started %d minutes ago; UNCOVERED is starting in %d minutes!",t,60-t):
p("UNCOVERED started %d minutes ago!",t-60);}

333 bytes after removing the unnecessary newlines (all but the one after the #define).

  • \$\begingroup\$ Not sure of the savings but you have some string literals you might be able to add like "minutes" and "UNCOVERED" \$\endgroup\$
    – Matt
    Apr 1, 2016 at 5:03

PHP, 347 328 327 322 bytes

<?=$u="UNCOVERED";$m=" minutes";$s=" started ";$p="re-show";$z=['P'=>0,'M'=>1,'C'=>2,'E'=>3];$i=explode(":",$argv[1]);$h=$i[0]%12-$z[$argv[2][0]];$o=$i[1];$t=60-$o;$a="$s$o$m ago";echo"It is ".(($h+11)%12+1).":$o".($h<0?" A":" P")."M PDT.\n".($h<6?$t."$m until the p$p!":($h<7?"P$p$a; $u is starting in $t$m!":"$u$a!"));?>

exploded view

  $u = "UNCOVERED";
  $m = " minutes";
  $s = " started ";
  $p = "re-show";
  $z = [ 'P' => 0,
         'M' => 1,
         'C' => 2,
         'E' => 3 ];

  $i = explode(":", $argv[1]);
  $h = $i[0]%12 - $z[$argv[2][0]];
  $o = $i[1];
  $t = 60 - $o;
  $a = "$s$o$m ago";

  echo "It is " . (($h+11)%12+1) . ":$o" . ($h < 0 ? " A" : " P") . "M PDT.\n" .
       ($h < 6 ? $t . "$m until the p$p!"
               : ($h < 7 ? "P$p$a; $u is starting in $t$m!"
                         : "$u$a!"));

Runs as php script.php HH:MM XDT. Takes in the time and time zone as $argv entries, regexes $argv[1] out into $i = [HH, MM], determines the time zone from the first character in $argv[2], maths out how many minutes past 6PM PDT that is, then ternaries the echo.

Could drop 2 bytes by using $u=UNCOVERED, but it'd be the only error here and I like that this works cleanly.


PowerShell 292 Bytes

$r,$i,$s,$u="re-show"," minutes"," start","UNCOVERED";$h,$m,$z=$args[0]-split":| ";$h=+$h-"PMCE".IndexOf($z[0]);"It is $h`:$m PM PDT.";if(($t=$h*60+$m-360)-lt0){"$($t*-1)$i until the p$r!"}else{if($t-gt59){"$u$s`ed $($t-60)$i ago!"}else{"P$r$s`ed $t$i ago; $u is$s`ing in $(($t-60)*-1)$i!"}}

Less Golfed Explanation

# Some string literals.
$r,$i,$s,$u,$g="re-show"," minutes"," start","UNCOVERED"," ago"
# Get the hours, minutes and zone into variables.
$h,$m,$z=$args[0]-split":| "
# Offset the time based on the passed timezone. 
$h=+$h - "PMCE".IndexOf($z[0])
# Display current PDT time.
"It is $h`:$m PM PDT."

# Based on adjusted time value for PDT determine what string to show. 
# Several string literals were used to save space.
    # Show has not started yet
    "$($t*-1)$i until the p$r!"
        # Between 6 and 7
        "$u$s`ed $($t-60)$i$g!"
        # It's after 7. Should have check more often. 
        "P$r$s`ed $t$i$g; $u is$s`ing in $(($t-60)*-1)$i!"

The literal for " ago" was removed in code but for now left in explanation in case of other changes.

  • \$\begingroup\$ I think I went overboard on some literals and it made it longer.... \$\endgroup\$
    – Matt
    Apr 1, 2016 at 5:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.