Skip to content

Commit 8dbc2bc

Browse files
committed
bugfix: 12am sometimes written as 'midday'
Use dt.hour directly for hourstring (it tests assuming the input is a 24h value; passing it 12h value already corrected results in 'midday in the morning' error)
1 parent 79c36e8 commit 8dbc2bc

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

jjrenderer/jjtimestring.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -244,17 +244,17 @@ def GetTimeString(dt=datetime.datetime.now(), lang="en"):
244244
r = random.randint(0,5)
245245
if r == 0 and dt.minute > 0:
246246
# type 0: "mmm past hhh"
247-
timestring = GetNumberString(dt.minute) + " Past " + GetHourString(h)
247+
timestring = GetNumberString(dt.minute) + " Past " + GetHourString(dt.hour)
248248
elif r == 1 and dt.minute % 15 == 0:
249249
# type 1: o'clock, quarter past, half past, quarter to
250250
if dt.minute == 0:
251251
timestring = GetNumberString(h, lang) + " O'Clock"
252252
elif dt.minute == 15:
253-
timestring = "Quarter Past " + GetHourString(h, "en").title()
253+
timestring = "Quarter Past " + GetHourString(dt.hour, "en").title()
254254
elif dt.minute == 30:
255-
timestring = "Half Past " + GetHourString(h).title()
255+
timestring = "Half Past " + GetHourString(dt.hour).title()
256256
elif dt.minute == 45:
257-
timestring = "Quarter To " + GetHourString(h1).title()
257+
timestring = "Quarter To " + GetHourString(dt.hour+1).title()
258258
elif r == 2 and dt.minute > 9:
259259
# type 2: "hhh mmm"
260260
timestring = GetNumberString(h) + " " + GetNumberString(dt.minute)
@@ -281,7 +281,7 @@ def GetTimeString(dt=datetime.datetime.now(), lang="en"):
281281
h = dt.hour
282282
if h == 0:
283283
h += 12
284-
timestring = "Half " + GetHourString(h).title()
284+
timestring = "Half " + GetHourString(dt.hour).title()
285285
elif lang=="en_mil":
286286
# type 3: military
287287
if dt.hour < 10:
@@ -299,21 +299,21 @@ def GetTimeString(dt=datetime.datetime.now(), lang="en"):
299299
timestring += " Hours"
300300
elif lang=="en_idiomatic":
301301
if dt.minute <= 5:
302-
timestring = "It's " + GetHourString(h) + "-ish"
302+
timestring = "It's " + GetHourString(dt.hour) + "-ish"
303303
elif dt.minute <= 10:
304-
timestring = "It's a tad after " + GetHourString(h)
304+
timestring = "It's a tad after " + GetHourString(dt.hour)
305305
elif dt.minute <= 20:
306-
timestring = "It's a fair bit after " + GetHourString(h)
306+
timestring = "It's a fair bit after " + GetHourString(dt.hour)
307307
elif dt.minute < 30:
308-
timestring = "It's nearly half " + GetHourString(h)
308+
timestring = "It's nearly half " + GetHourString(dt.hour)
309309
elif dt.minute == 30:
310-
timestring = "It's Half " + GetHourString(h).title()
310+
timestring = "It's Half " + GetHourString(dt.hour).title()
311311
elif dt.minute <= 40:
312-
timestring = "It's a touch after half past " + GetHourString(h)
312+
timestring = "It's a touch after half past " + GetHourString(dt.hour)
313313
elif dt.minute <= 55:
314-
timestring = "It's banging on towards " + GetHourString(h1)
314+
timestring = "It's banging on towards " + GetHourString(dt.hour+1)
315315
else:
316-
timestring = "It's a smidge before " + GetHourString(h1)
316+
timestring = "It's a smidge before " + GetHourString(dt.hour+1)
317317

318318
elif lang=="en_oz":
319319
r2 = random.randint(0,9) # 20% profanity
@@ -325,29 +325,29 @@ def GetTimeString(dt=datetime.datetime.now(), lang="en"):
325325
if dt.minute <= 5:
326326
r2 = random.randint(0,9) # profanity 10%
327327
if r2 == 0:
328-
timestring = "It's a bee's dick past " + profanity + GetHourString(h)
328+
timestring = "It's a bee's dick past " + profanity + GetHourString(dt.hour)
329329
else:
330-
timestring = "It's a bee's whisker past " + profanity + GetHourString(h)
330+
timestring = "It's a bee's whisker past " + profanity + GetHourString(dt.hour)
331331
elif dt.minute <= 10:
332-
timestring = "It's a " + profanity + "tenner or so past " + GetHourString(h)
332+
timestring = "It's a " + profanity + "tenner or so past " + GetHourString(dt.hour)
333333
elif dt.minute <= 20:
334-
timestring = "It's a fair " + profanity + "wack after " + GetHourString(h)
334+
timestring = "It's a fair " + profanity + "wack after " + GetHourString(dt.hour)
335335
elif dt.minute < 30:
336336
r2 = random.randint(0,1)
337337
if r2 == 0:
338-
timestring = "Hold ya " + profanity + "horses it's nearly half past " + GetHourString(h)
338+
timestring = "Hold ya " + profanity + "horses it's nearly half past " + GetHourString(dt.hour)
339339
else:
340-
timestring = "It's cooee of half past " + profanity + GetHourString(h)
340+
timestring = "It's cooee of half past " + profanity + GetHourString(dt.hour)
341341
elif dt.minute == 30:
342-
timestring = "It's bang on half past " + profanity + GetHourString(h)
342+
timestring = "It's bang on half past " + profanity + GetHourString(dt.hour)
343343
elif dt.minute <= 40:
344-
timestring = "It's a blouse after half past " + profanity + GetHourString(h)
344+
timestring = "It's a blouse after half past " + profanity + GetHourString(dt.hour)
345345
elif dt.minute <= 55:
346-
timestring = "Hang on a tick and it'll be " + profanity + GetHourString(h1)
346+
timestring = "Hang on a tick and it'll be " + profanity + GetHourString(dt.hour+1)
347347
if dt.hour == 23 and random.randint(0,1) == 0: # 50% chance of harold holt
348348
timestring = "Today's about to chuck a " + profanity + "Harold"
349349
else:
350-
timestring = "It's a smidge before " + profanity + GetHourString(h1)
350+
timestring = "It's a smidge before " + profanity + GetHourString(dt.hour+1)
351351
if random.randint(0,2) == 0: # 1/3 of the time stick in 'o'clock'
352352
timestring += " o'clock"
353353
if dt.hour <= 3:

0 commit comments

Comments
 (0)