[Question]
  [
# dary!
In events entirely unrelated to [what will hopefully happen to me](https://codegolf.stackexchange.com/help/badges/27/legendary) in the next couple of days, I task you to write code that does the following:
1. Print
```
Legen... wait for it...
```
immediately, with a trailing newline.
2. Wait until the next full hour (when the cron job for awarding the badge runs).
3. Print
```
dary!
```
with an *optional* trailing newline.
### Additional rules
* You may write a program or a function, but the output has to be printed to STDOUT (or its closest alternative of your language).
* You have to wait until the next *full* hour, not just for 60 minutes. If the code is run at 6:58, it should print the second line at 7:00.
* The last line must be printed no later than one second after the next full hour.
* In the event that the program is started in the first second of a full hour, it should it wait for the next full hour.
* You may query local or UTC time.
* Standard [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") rules apply.
  
[Answer]
# JavaScript (ES6), 74 bytes
You may want to change your system clock before testing, congratulations if you landed here at 59 minutes past.
```
setTimeout(a=alert,36e5-new Date%36e5,"dary!");a`Legen... wait for it...
`
```
[Answer]
# Pyth, ~~42~~ 41
```
J.d6." wâ«­hÖ`Ùá©h´^"WqJ.d6;"dary!
```
Below is a hexdump of the code:
```
00000000  4a 2e 64 36 2e 22 20 77  0c 10 89 e2 ab 1b ad 68  |J.d6." w.......h|
00000010  0f 8c d6 60 d9 e1 a9 68  82 b4 5e 22 57 71 4a 2e  |...`...h..^"WqJ.|
00000020  64 36 3b 22 64 61 72 79  21                       |d6;"dary!|
```
Saved 1 byte thanks to @isaacg
Uses the `.d` function to get local time related values. `.d6` returns the current hour. This prints the first string, then waits until the hour is different from the hour ad the start of the program, and then prints the second string.
You could try it online with `.d7` or `.d8` for minutes/seconds but the online compiler only prints anything when the program terminates.
Congrats, Dennis! :)
[Answer]
## CJam, ~~49~~ 48 bytes
```
et3="Legen... wait for it...
"o{_et3==}g;"dary!"
```
Uses local time. For testing purposes, you can replace the two instances of `3` with `4` or `5` to make it print at the start of the next minute/second.
[Test it here.](http://cjam.aditsu.net/#code=et3%3D%22Legen...%20wait%20for%20it...%0A%22o%7B_et3%3D%3D%7Dg%3B%22dary!%22) But note that the online interpreter doesn't show any output until the program terminates. Alternatively, you can run it on [Try it online](http://cjam.tryitonline.net/#code=ZXQzPSJMZWdlbi4uLiB3YWl0IGZvciBpdC4uLgoib3tfZXQzPT19ZzsiZGFyeSEi&input=), where the output is shown *almost* immediately instead of being buffered (but when you test it with seconds instead of hours, the delay will be noticeable). In any case, if you run it locally with the Java interpreter, it works like a charm.
### Explanation
This makes use of CJam's `et` which gives you an array of
```
[year month day hour minute second ms weekday utc_offset]
```
Here is a breakdown of the code:
```
et3=       e# Get the current hour.
"Legen..." e# Push the first string including the linefeed.
o          e# Print it.
{          e# While the top of stack is truthy (which is popped)...
  _        e#   Copy the original hour.
  et3=     e#   Get the current hour.
  =        e#   Check for equality.
}g
;          e# Discard the original hour.
"dary!"    e# Push the second string which is printed automatically.
```
### Bonus
This also works for the same byte count:
```
et4<"Legen... wait for it...
"o{et1$#!}g;"dary!"
```
Instead of selecting the hour, we're selecting the prefix with the date *and* the hour, and keep the loop going while the datetime array still has that prefix.
[Answer]
# AppleScript, ~~157~~ 149 bytes
Huh. Surprisingly contending.
```
set d to number 1 in time string of(current date)
log"Legen... wait for it..."
repeat while d=number 1 in time string of(current date)
end
log"dary!"
```
Since `log` prints to the Messages pane of Script Editor, I consider it to be the closest output to STDOUT. Basically, if you get the time string of current date, it'll do something like this:
Code:
```
time string of(current date)
```
Output:
```
5:02:03 PM
```
It will grab the first number (`5`) before the colon.
I thought it'd be a lot longer than this, actually. xD
[Answer]
## [Snowman 1.0.2](https://github.com/KeyboardFire/snowman-lang/releases/tag/v1.0.2-beta), ~~70~~ 69 bytes
```
~"Legen... wait for it...
"sP3600000*vt#nDnC!*:vt+#nD!#nL;bD"dary!"sP
```
Explanation:
```
~              Make all variables active.
"..."sP        Print the first string.
3600000*vt#nD  Get the number of hours since the Unix epoch.
nC             Ceiling (round up), giving the time (divided by 36000) at which to
                 print the second string.
!*             Save that in a permavar.
:...;bD        Do the stuff in the block while its "return value" is truthy.
  vt+#nD       Again, get the number of hours since epoch.
  !#             Store the permavar that we saved earlier.
  nL             Is the current time less than the target time? (if so,
                   keep looping)
"..."sP        Print the second string.
```
[Answer]
# PHP, 76, 70, 65, 62 51 bytes
```
Legen... wait for it...
<?while(+date(is));?>dary!
```
Previous logic (63b):
```
Legen... wait for it...
<?for($h=date(G);date(G)==$h;)?>dary!
```
This kind of coding makes you loose your job, but this loops until the time is 1 hour further than init.
-1 byte by replacing `{}` afer the while to `;` (thanks manatwork)  
-5 bytes by replacing `echo'dary!';` to `?>dary!` (thanks manatwork)  
-4 bytes by replacing `<?php` to the short version `<?` (thanks primo)  
-1 byte by replacing the `while` for a `for`  
-3 bytes by replacing `date(G)!=$h+1` to `date(G)==$h` (thanks primo)
[Answer]
## [Perl 6](http://perl6.org), 60 bytes
```
sleep 60²-now%60²+say 'Legen... wait for it..';say 'dary!'
```
[Answer]
# Javascript 94 90 87 bytes
Not golfed that much...
```
alert`Legen... wait for it...`,l=l=>~~(Date.now()/36e5);for(z=l();z==l(););alert`dary!`
```
Downgoat's version:
```
(a=alert)`Legen... wait for it...`,z=(b=new Date().getHours)();for(;z==b(););a`dary!`
```
It stores the current hour and loops for as long as the "old" hour is equal to the current one. As soon as the hour has changed, it will print the rest! :D
Disclaimer:
If your browser dislikes it, you have been warned.
[Answer]
# Python 2, ~~82~~ 81 bytes
```
from time import*;print'Legen... wait for it...';sleep(-time()%3600);print'dary!'
```
Too low a reputation to comment. Python 2 version of Alexander Nigl's solution. Saves characters lost on brackets. Also, 3600 not needed in the sleep time calculation.
7 characters saved overall.
Edit: -1 byte thanks to @Kevin Cruijssen
[Answer]
# MATLAB - 89 bytes
```
a=@()hour(now);disp('Legen... wait for it...');while(mod(a()+1,24)~=a())end;disp('dary!')
```
Pretty self-explanatory. First, create a function handle to grab the current hour of the system clock. Then, display `Legen... wait for it...` with a carriage return, and then we go into a `while` loop where we keep checking to see if the current hour added with 1 is **not** equal to the current hour. If it is, keep looping. Only until the instant when the next hour happens, we display `dary!` and a carriage return happens after.
MATLAB's hour is based on 24-hour indexing, so the `mod` operation with base 24 is required to handle spilling over from 11 p.m. (23:00) to midnight (00:00).
## Minor Note
The [`hour`](http://www.mathworks.com/help/finance/hour.html) function requires the Financial Time Series toolbox. The [`now`](http://www.mathworks.com/help/matlab/ref/now.html) function is not subject to this restriction, but it retrieves the current date and time as a serial number which `hour` thus uses to compute the current hour.
## Want to run this in Octave?
Sure! Because Octave doesn't have this toolbox, we'd just have to modify the `hour` function so that it calls [`datevec`](http://www.mathworks.com/help/matlab/ref/datevec.html) which returns a vector of 6 elements - one for each of the year, month, day, hour, minutes and seconds. You'd just have to extract out the fourth element of the output:
```
a=@()datevec(now)(4);disp('Legen... wait for it...');while(mod(a()+1,24)~=a())end;disp('dary!')
```
The additional characters make the solution go up to 98 bytes, but you'll be able to run this in Octave. Note the in-place indexing without a temporary variable in the function handle.
# No Financial Time Series Toolbox?
If you want to run this in MATLAB **without** the Financial Time Series Toolbox, because you can't index into variables immediately without at temporary one, this will take a bit more bytes to write:
```
disp('Legen... wait for it...');h=datevec(now);ans=h;while(mod(h(4)+1,24)~=ans(4)),datevec(now);end;disp('dary!');
```
This first obtains the current time and date and stores it into the variable `h` as well as storing this into the automatic variable called `ans`. After, we keep looping and checking if the current hour isn't equal to the next hour. At each iteration, we keep updating the automatic variable with the current time and date. As soon as the next hour matches with the current time and date, we display the last part of the string and quit. This pushes the byte count to 114.
---
Also take note that you can't try this online. Octave interpreters online will have a time limit on when code executes, and because this is a `while` loop waiting for the next hour to happen, you will get a timeout while waiting for the code to run. The best thing you can do is run it on your own machine and check that it works.
[Answer]
## Mathematica, ~~85~~ ~~84~~ 81 bytes
```
c=Print;c@"Legen... wait for it...";a:=DateValue@"Hour";b=a;While[a==b];c@"dary!"
```
[Answer]
# C, 163 bytes
```
#include<time.h>
f(){puts("Legen... wait for it...");time_t t=time(0);struct tm l=*localtime(&t);while(l.tm_min+l.tm_sec)t=time(0),l=*localtime(&t);puts("dary!");}
```
[Answer]
# Microscript II, 45 bytes
```
"Legen... wait for it..."P[36s5E*sD%_]"dary!"
```
Finally, a use for the `D` instruction.
Prints the first string, repeatedly takes the UTC time in milleseconds modulo 3,600,000 until this yields 0, and then produces the second string which is printed implicitly. The 3,600,000 is represented in the code as 36x105.
[Answer]
## TI-BASIC, ~~70~~ 64 bytes
```
getTime
Disp "Legen... wait for it...
Repeat sum(getTime-Ans,1,1
End
"dary
```
*Curse these two-byte lowercase letters!*
`getTime` returns a three-element list `{hours minutes seconds}`, so the sum from the 1st element to the 1st is the hours. When there is a difference between the hours at the start and the current hours, the loop ends. Thanks to @FryAmTheEggman for this observation.
[Answer]
# R - 97 bytes
```
cat('Legen... wait for it...\n')
Sys.sleep(1)
while(as.double(Sys.time())%%3600>0){}
cat('dary!')
```
[Answer]
# Perl, 62 bytes
```
sleep -++$^T%3600+print'Legen... wait for it...
';print'dary!'
```
The special variable [`$^T`](http://perldoc.perl.org/perlvar.html#%24%5eT) (a.k.a `$BASETIME`) records the number seconds since epoch from when the script was started. Fortunately, leap seconds are not counted in the total, so that the following are equivalent:
```
print$^T%3600;
@T=gmtime;print$T[1]*60+$T[0];
```
Surprisingly, this variable is not read-only.
[Answer]
# Python 3 - 92 89 bytes
```
from time import*;print("Legen... wait for it...");sleep(3600-time()%3600);print("dary!")
```
[Answer]
# Windows Command Script, 87 bytes
```
@set.=%time:~,2%&echo.Legen... wait for it...
:.
@if %.%==%time:~,2% goto:.
@echo.dary!
```
This continually compares an hour-variable stored at start against the current hour and succeeds if different.
[Answer]
# [Japt](https://github.com/Japt/ETHproductions), ~~72~~ 61 bytes
```
`{?tT?e?t(Ã?t,36e5-?w D?e%36e5,'ÜÝ!'),'Leg?... Ø2 f? ?...\n'}
```
Each `?` represents a Unicode unprintable char. Here's how to obtain the full text:
1. Open the [online interpreter](https://codegolf.stackexchange.com/a/62685/42545).
2. Paste this code into the Code box:
```
Oc"`\{setTimeout(alert,36e5-new Date%36e5,'dary!'),'Legen... wait for it...\\n'}
```
3. Run the code, then erase it from the Code box.
4. Select the contents of the Output box and **drag** to the Code box. **Copy-pasting will not work**.
5. Replace the first space with a non-breaking space.
6. (optional) Set your computer's clock to xx:59.
7. Run the code.
Alternatively, here is a (hopefully reversible) hexdump:
```
00000000: 607b a074 548b 658c 7428 c300 742c 3336 65    `{ tT?e?t(Ã?t,36e
00000011: 352d 9a77 2044 8565 2533 3665 352c 27dc dd    5-?w D?e%36e5,'ÜÝ
00000022: 2127 293b 274c 6567 812e 2e2e 20d8 3220 66    !'),'Leg?... Ø2 f
00000033: 8e20 8a2e 2e2e 5c6e 277d                      ? ?...\n'}
```
This code is based on [George Reith's JavaScript answer](https://codegolf.stackexchange.com/a/64885/42545), with a few Japt-specific changes. [I found out the other day](https://codegolf.stackexchange.com/a/64790/42545) that if you compress code and insert it into a backtick-wrapped string, it will automatically decompress. Here's how it's processed through compilation:
```
`{?tT?e?t(Ã?t,36e5-?w D?e%36e5,'ÜÝ!'),'Leg?... Ø2 f? ?...\n'}
"{setTimeout(alert,36e5-new Date%36e5,'dary!'),'Legen... wait for it...\n'}"
""+(setTimeout(alert,36e5-new Date%36e5,'dary!'),'Legen... wait for it...\n')+""
```
In JS, a pair of parentheses will return the last value inside; thus, this code sets the timed event, then returns the `'Legen...'` string, which is automatically sent to STDOUT. Since Japt currently has no way to add content to STDOUT other than automatic output on compilation, I've instead used the vanilla JS function `alert` for the timed output. I hope this is allowed.
[Answer]
# Powershell, ~~52~~ 51 bytes
*-1 byte thanks @Veskah*
```
'Legen... wait for it...'
for(;Date|% M*e){}'dary!'
```
This expression `Date|% M*e` gets value from `Minute` property from the Current DateTime value. The loop ends when `Minute` equal to 0. 
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~48 47~~ 45 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
-1 byte thanks to Erik the Golfer (use "Leg" as a word in the compression)  
-2 thanks to caird coinheringaahing
```
“ÇỴġƒḃhlḂṀ⁷*Ḣ¡w*Jḷv»Ṅø3ŒTṣ”:V59_ḅ60‘œS@“dary!
```
**[Try it online!](https://tio.run/##AVoApf9qZWxsef//4oCcw4fhu7TEocaS4biDaGzhuILhuYDigbcq4biiwqF3KkrhuLd2wrvhuYTDuDPFklThuaPigJ06VjU5X@G4hTYw4oCYxZNTQOKAnGRhcnkh//8 "Jelly – Try It Online")** Or [run a test version](https://tio.run/##AWEAnv9qZWxsef//4oCcw4fhu7TEocaS4biDaGzhuILhuYDigbcq4biiwqF3KkrhuLd2wrvhuYTDuOKAnDU5OjU34oCd4bmj4oCdOlY1OV/huIU2MOKAmMWTU0DigJxkYXJ5If// "Jelly – Try It Online") with a hard coded time-formatted-string of `“59:57”` ("mm:ss"). (Note: TIO buffers output, but local runs work as expected.)
There is, at the time of writing, only one way to access the time which is by way of a formatted string, `ŒT`.
This code calculates how long to wait and then sleeps. If called at `hh:00:00` it waits for `3600` seconds: it converts `"00:00"` to `[0,0]` then subtracts that from `59` to yield `[59,59]`, converts that from base sixty to give `3599`, then adds one for a total wait period of `3600` seconds.
Maybe a loop could be made; or a compressed string using the whole word "Legendary" could be utilised somehow?
```
“ÇỴġƒḃhlḂṀ⁷*Ḣ¡w*Jḷv»Ṅø3ŒTṣ”:V59_ḅ60‘œS@“dary! - Main link: no arguments
“ÇỴġƒḃhlḂṀ⁷*Ḣ¡w*Jḷv»                          - compressed "Legen... wait for it..."
                    Ṅ                         - print z + '\n', return z
                     ø                        - niladic chain separation
                      3ŒT                     - '011' (3) time formatted string = "mm:ss"
                         ṣ”:                  - split on ':' -> ["mm","ss"]
                            V                 - eval -> [m,s]
                             59_              - subtract from 59 - > [59-m, 59-s]
                                 ḅ60          - convert from base 60 -> 60*(59-m)+(59-s)
                                    ‘         - increment -> 60*(59-m)+(59-s) = y
                                       “dary! - "dary!" = x
                                     œS@      - sleep y seconds then return x
                                              - implicit print
```
[Answer]
## Python, 112 bytes
```
import time as t;print "Legen... wait for it...";n=t.ctime();t.sleep((60-n.tm_min)*60+60-n.tm_sec);print "dary!"
```
Pretty self explanatory.
[Answer]
## Python - 159 bytes
```
from datetime import*;from threading import*;p=print;n=datetime.now();p('Legen... wait for it...');Timer(3600-(n.minute*60+n.second),lambda:p('dary!')).start()
```
[Answer]
# [Mouse-2002](https://github.com/catb0t/mouse15), 62 bytes
Requires the user to press enter. I think.
```
"Legen... wait for it..."?&HOUR 1+x:(&HOUR x.=["dary"33!'0^])
```
---
Okay, well, while we're taking lots of bytes and not winning anything, let's have a little fun.
```
"Legen... wait for it... "?     ~ print & require keypress
&HOUR 1+ x:                     ~ get hr, add 1 and assign
(                               ~ while(1)
  &HOUR x. =                    ~ cmp current hr, stored hr
  [                             ~ if same
    #B;                           ~ backspace
    "dary"36!'                    ~ print this string and a !
    0^                            ~ exit cleanly
  ]                             ~ fi
  &MIN 59 - &ABS !              ~ get min, subtract from 59, abs & print
  ":"                           ~ record sep
  &SEC 59 - &ABS !              ~ same for second
  #B;                           ~ backspace
)
$B 8!' 8 !' 8 !' 8 !' 8 !'@     ~ backspace 5*
$                               ~ \bye
```
Sample:
```
$ mouse legend.m02
Legen... wait for it... 20:32
```
See, it's an updating-in-place countdown timer to the next hour! It makes good use of the while loop, which even doing nothing at all will occupy a core.
[Answer]
# BASIC, 90 bytes
```
Print"Legen... wait for it...":x$=Left(Time,2):Do:Loop Until x$<>Left(Time,2):Print"dary!"
```
Straightforward, golfed using the type prefixes and the implicit `End` statement. Cost is that it works only in [FreeBasic](http://www.freebasic.net/) dialect `fblite`.
[Answer]
# Befunge 98 - ~~69~~ 63 bytes
```
 v
v>a"...ti rof tiaw ...negeL<ETB>"k,
>"EMIT"4(MS+_"!yrad"5k,@
```
The code contains one unprintable character (represented by `<ETB>` as unprintables don't seem to show up in code blocks). Its character code is 23 (an [End transmission block character](https://en.wikipedia.org/wiki/End_Transmission_Block_character)).
Warning: The preceding code will run in a busy loop with the stack getting bigger each repetition and thus may consume large amounts of memory.
[Answer]
# [MathGolf](https://github.com/maxbergmark/mathgolf), 39 bytes
```
"Legen... wait for it..."pÆt♪/╚÷▼"dary!
```
[Try it online!](https://tio.run/##y00syUjPz0n7/1/JJzU9NU9PT0@hPDGzRCEtv0ghswTIVSo43FbyaOYqfePD2x9N26OUklhUqfj/PwA "MathGolf – Try It Online")
Almost beat pyth... 
## Explanation
```
Æ     ▼  Repeat the next 5 characters while false
 t       push unix time in milliseconds
  ♪/     divide by 1000
    ╚÷   check if divisible by 3600 (tio solution has 3 in its place)
```
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal) `o`, 36 bytes
```
`Le₁ǐ... ʁṁ λ⟑ it...`,kḢ{:kḢ=|}`d₴⁼!
```
[Don't Try it Online!](https://lyxal.pythonanywhere.com?flags=o&code=%60Le%E2%82%81%C7%90...%20%CA%81%E1%B9%81%20%CE%BB%E2%9F%91%20it...%60%2Ck%E1%B8%A2%7B%3Ak%E1%B8%A2%3D%7C%7D%60d%E2%82%B4%E2%81%BC!&inputs=&header=&footer=)
In the online interpreter, all output happens at once, so you can't see exactly what's happening. However, if you download and run the interpreter, you can see that it functions as expected.
Explanation:
```
`Le₁ǐ... ʁṁ λ⟑ it...`                # Dictionary-compressed string "Legen... wait for it..."
                     ,               # Print with newline
                      kḢ{:kḢ= }      # While the current hour hasn't changed:
                             |       #  Do nothing
                               `d₴⁼! # Dictionary-compressed string "dary!"
                                     # "o" flag - Force implicit output
```
[Answer]
# Pyth - 36 bytes
Waits till the minutes is 0 with a while loop.
```
"Legen... wait for it..."W.d7)"dary!
```
[Answer]
# Java, 136 bytes
```
class a{void A(){System.out.println("Legen... wait for it...");while(System.currentTimeMillis()%3600000!=0);System.out.print("dary!");}}
```
How many milliseconds passed since the last full hour is the result of `System.currentTimeMillis()` mod 3,600,000.
The equivalent monolithic program is 159 bytes long:
```
interface a{static void main(String[]A){System.out.println("Legen... wait for it...");while(System.currentTimeMillis()%3600000!=0);System.out.print("dary!");}}
```
]