Files
matrixclock/helpers.py

112 lines
3.3 KiB
Python

import settings
def Time2Sentence(TimeArray):
minute=TimeArray[4]
hour=(TimeArray[3]+settings.timezone)%24
MinuteString=["",
"m1 past",
"m2 past",
"m3 past",
"m4 past",
"m5 past",
"m6 past",
"m7 past",
"m8 past",
"m9 past",
"m10 past",
"m11 past",
"m12 past",
"m13 past",
"m14 past",
"quarter past",
"m16 past",
"m17 past",
'm18 past',
'm19 past',
'm20 past',
'm20 m1 past',
'm20 m2 past',
'm20 m3 past',
'm20 m4 past',
'm20 m5 past',
'm20 m6 past',
'm20 m7 past',
'm20 m8 past',
'm20 m9 past',
'half past',
'm20 m9 to',
'm20 m8 to',
'm20 m7 to',
'm20 m6 to',
'm20 m5 to',
'm20 m4 to',
'm20 m3 to',
'm20 m2 to',
'm20 m1 to',
'm20 to',
'm19 to',
'm18 to',
'm17 to',
'm16 to',
'quarter to',
'm14 to',
'm13 to',
'm12 to',
'm11 to',
'm10 to',
'm9 to',
'm8 to',
'm7 to',
'm6 to',
'm5 to',
'm4 to',
'm3 to',
'm2 to',
'm1 to',
]
HourString=['midnight',
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'h7',
'h8',
'h9',
'h10',
'h11',
'h12',
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'h7',
'h8',
'h9',
'h10',
'h11',
'midnight',
]
TimeString='it is'
TimeString += ' '+MinuteString[minute]
if TimeString[-2:] == 'to':
TimeString += " "+HourString[hour+1]
else:
TimeString += " "+HourString[hour]
if minute == 0 and TimeString[-8:] != 'midnight':
TimeString += " oclock"
if 0 < hour < 12 and TimeString[-2:] != '12':
TimeString += " in the morning"
if 12 < hour <= 17:
TimeString += " in the afternoon"
if 17 < hour <= 21:
TimeString += " in the evening"
if 21 < hour <= 24 and TimeString[-8:] != 'midnight':
TimeString += " at night"
return TimeString