Python 2.7, 131 128 121 bytes:
from datetime import*;S=lambda f:int(datetime.utcnow().strftime(f));print'%03.0f'%(((S('%H')+1%24)*3600+S('%M')*60)/86.4)
A full program that outputs the Swatch Internet Time.
Simply uses Python's built in datetime
module to first get the UTC+0
time in hours and minutes using datetime.utfnow().strftime('%H')
and datetime.utfnow().strftime('%M')
, respectively. Then, the time is converted into UTC+1
by adding 1
to the hours and then modding the sum by 24
to ensure the result is in the 24-hour range. Finally, the hour is turned into its equivalent in seconds, which is added to the minute's equivalent in seconds, and the resulting sum is divided by 86.4
, as there are 86.4
seconds or 1 min. 24 sec.
in 1 ".beat", after which, using string formatting, the quotient is rounded to the nearest integer and padded with zeroes until the length is 3
.
However, I am not the one to stop here. In the above solution, I used a more direct method to convert the time to UTC+1
. However, wanted to add a bit of a bigger challenge for myself and implement this using only Python's built in time
module, which apparently does not have any built-in method that I know of to convert local time into UTC+0
time. So now, without further ado, here is the perfectly working version using only the time module, currently standing at 125 bytes:
from time import*;I=lambda g:int(strftime(g));print'%03.0f'%((((I('%H')+1-daylight)%24*3600+timezone)%86400+I('%M')*60)/86.4)
This can output the correct Swatch Internet Time for any and all time zones, and basically does pretty much everything the same as in the first solution, except this time converts the local time into UTC+1
by first adding 1
to the hour, and then subtracting 1
if daylight-savings time is currently, locally observed, or 0
otherwise. Then, this difference is modded by 24
to ensure that the result stays within the 24
hour range, after which it is multiplied by 3600
for conversion into seconds. This product is then added to the result from the built-in timezone
method, which returns the local offset from UTC+0
. After this, you finally have your hours in UTC+1
. This then continues on from here as in the first solution.