kas/qtime
2
3
Fork
You've already forked qtime
0

Algorithm of calculation #4

Closed
opened 2021年06月05日 19:00:44 +02:00 by PapillonAll · 9 comments
PapillonAll commented 2021年06月05日 19:00:44 +02:00 (Migrated from github.com)
Copy link

I understood the C source of qtime, however, I didn't understand why you did your calculation that way. So, could you please explain it to me or point me to the original algorithm of your calculation.

I understood the C source of qtime, however, I didn't understand why you did your calculation that way. So, could you please explain it to me or point me to the original algorithm of your calculation.
kseistrup commented 2021年06月05日 19:42:11 +02:00 (Migrated from github.com)
Copy link

You are seeing the original algorithm.

Back around 1990 there was a tiny closed-source commandline program for the Amiga named qt, written by one of the authors of the BBS frontend TrapDoor. I wrote my own implementation back then, in MC68k assembler. I was an self-taught amateur hobby programmer at that time, and I still am today.

I can't tell you now why I reasoned like I did 30 years ago. Is there something in particular that you find odd?

You are seeing the original algorithm. Back around 1990 there was a tiny closed-source commandline program for the Amiga named `qt`, written by one of the authors of the BBS frontend `TrapDoor`. I wrote my own implementation back then, in MC68k assembler. I was an self-taught amateur hobby programmer at that time, and I still am today. I can't tell you now why I reasoned like I did 30 years ago. Is there something in particular that you find odd?
kseistrup commented 2021年06月05日 20:13:31 +02:00 (Migrated from github.com)
Copy link

QTime is a 12 hour clock with a granularity of 1 minute. For every 5-minute interval, two divisions will be ‘to’ (‘nearly’ and ‘almost’), one will be on the spot and two will be ‘past’ (‘just after’ and ‘after’). So it's all about finding the right 5-minute interval in the right hour on a 12-hour clock and finally finding which of the 1-minute divisions we're gonna use within said 5-minute interval.

QTime is a 12 hour clock with a granularity of 1 minute. For every 5-minute interval, two divisions will be ‘to’ (‘nearly’ and ‘almost’), one will be on the spot and two will be ‘past’ (‘just after’ and ‘after’). So it's all about finding the right 5-minute interval in the right hour on a 12-hour clock and finally finding which of the 1-minute divisions we're gonna use within said 5-minute interval.
PapillonAll commented 2021年06月06日 09:29:31 +02:00 (Migrated from github.com)
Copy link

It is the adjustment of the minutes that is difficult to grasp for me. Why did you add 30 seconds and 27 minutes to convert the number of seconds obtained by the get_secs function to get the adjusted number of minutes?

It is the adjustment of the minutes that is difficult to grasp for me. Why did you add 30 seconds and 27 minutes to convert the number of seconds obtained by the get_secs function to get the adjusted number of minutes?
kseistrup commented 2021年06月06日 09:51:18 +02:00 (Migrated from github.com)
Copy link

At half past we still refer to the current hour, e.g., 12:30 is ‘half past twelve’. Because of the 1-minute granularity we then say ‘just after half past twelve’ (12:31) and ‘after half past twelve’ (12:32) before we switch to the next hour: 12:33 is ‘nearly twenty-five to one’. So in order to calculate the right hour we round up by adding 27.5 minutes to the actual minutes. This also gives us the right number of minutes, since our minutes only go from 0 (‘o'clock’) to 30 (‘half past’), not from 0 to 59.

I haven't thought it through, but perhaps you could achieve the same by adding half an hour and do a modulus 30, but 30 years ago my brains decided to use the algorithm you see.

At half past we still refer to the current hour, e.g., 12:30 is ‘half past twelve’. Because of the 1-minute granularity we then say ‘just after half past twelve’ (12:31) and ‘after half past twelve’ (12:32) before we switch to the next hour: 12:33 is ‘nearly twenty-five to one’. So in order to calculate the right hour we round up by adding 27.5 minutes to the actual minutes. This also gives us the right number of minutes, since our minutes only go from 0 (‘o'clock’) to 30 (‘half past’), not from 0 to 59. I haven't thought it through, but perhaps you could achieve the same by adding half an hour and do a modulus 30, but 30 years ago my brains decided to use the algorithm you see.
PapillonAll commented 2021年06月07日 07:42:53 +02:00 (Migrated from github.com)
Copy link

Is 27.5 minutes coming from the fact that 55/2=27.5?

Is 27.5 minutes coming from the fact that 55/2=27.5?
kseistrup commented 2021年06月07日 08:32:55 +02:00 (Migrated from github.com)
Copy link

27.5 minutes is coming from the fact that it is what is remaining when you're halfway between HH:32 and HH:33: (60−(32+33)/2 == 27.5). I.e., at HH:32:30 you go from saying "It's after HH" to "It's nearly twenty-five to HH+1", so adding 27.5 minutes is like rounding up to the next pronounced hour (HH+1) the same way adding 0.5 to a decimal and then rounding to the nearest integer will round up arithmetically.

27.5 minutes is coming from the fact that it is what is remaining when you're halfway between HH:32 and HH:33: (60−(32+33)/2 == 27.5). I.e., at HH:32:30 you go from saying "It's after HH" to "It's nearly twenty-five to HH+1", so adding 27.5 minutes is like rounding up to the next pronounced hour (HH+1) the same way adding 0.5 to a decimal and then rounding to the nearest integer will round up arithmetically.
kseistrup commented 2021年06月07日 08:36:13 +02:00 (Migrated from github.com)
Copy link

PS: And the reason we use 27.5 minutes to round up, and not 30 minutes, is that when we pronounce the time, HH:31 and HH:32 still belongs to "half past HH", so they shouldn't be rounded up to HH+1.

PS: And the reason we use 27.5 minutes to round up, and not 30 minutes, is that when we pronounce the time, HH:31 and HH:32 still belongs to "half past HH", so they shouldn't be rounded up to HH+1.
PapillonAll commented 2021年06月07日 09:22:52 +02:00 (Migrated from github.com)
Copy link

Thank you very much.

Your solution of the problem is succinct and clever. I studied the solution of the original program you mentioned earlier (maybe it is this one: https://ftp.fau.de/aminet/util/time/QTime.readme ), the solution was simpler but more lines of code.

Thank you very much. Your solution of the problem is succinct and clever. I studied the solution of the original program you mentioned earlier (maybe it is this one: https://ftp.fau.de/aminet/util/time/QTime.readme ), the solution was simpler but more lines of code.
kseistrup commented 2021年06月07日 09:41:06 +02:00 (Migrated from github.com)
Copy link

Thanks for the link, I can see the author uses a completely different approach.

I'm pretty sure it is not the original qt program I had. The one I'm thinking of was written by Martin Laubach (who authored TrapDoor with Maximilian Hantsch).

I'm sure several people has implemented this. There was also a qt.rex REXX script included with the ooRexx distribution at one point.

Personally, I've found it's funnier to implement QTime whenever I try out a new programming language, than the usual "Hello, World!" program. I've also written implementations in Idris and Rebol, among others, but I no longer have the sources. My implementation in MC68k assembler is also gone, sadly.

Thanks for the link, I can see the author uses a completely different approach. I'm pretty sure it is not the original `qt` program I had. The one I'm thinking of was written by Martin Laubach (who authored `TrapDoor` with Maximilian Hantsch). I'm sure several people has implemented this. There was also a `qt.rex` REXX script included with the ooRexx distribution at one point. Personally, I've found it's funnier to implement QTime whenever I try out a new programming language, than the usual "Hello, World!" program. I've also written implementations in Idris and Rebol, among others, but I no longer have the sources. My implementation in MC68k assembler is also gone, sadly.
Sign in to join this conversation.
No Branch/Tag specified
master
fish3
No results found.
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
kas/qtime#4
Reference in a new issue
kas/qtime
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?