Bug 460684 - Support timestamps as number system
Summary: Support timestamps as number system
Status: REPORTED
Alias: None
Product: kcalc
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR wishlist
Target Milestone: ---
Assignee: Evan Teran
URL:
Keywords:
: 21190 (view as bug list)
Depends on:
Blocks:
 
Reported: 2022-10-18 20:01 UTC by Thomas Fischer
Modified: 2024-04-05 23:56 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Fischer 2022-10-18 20:01:48 UTC
In addition to decimal, octal, or binary number systems, kcalc should support timestamps as number systems.
For example, if the user enters "0:30.5" this should be interpreted as 30 seconds and 500 milliseconds. Adding another number like "0:42" should be possible, resulting in the output of "1:12.5".
It should be possible to do multiplications and divisions of timestamps with "regular" numbers. For example, "1:20" divided by 5 should give "0:16".

For internal purposes, user-entered timestamp strings can be converted to a floating-point number.
For example, the following regular expression can be used to make sense of the user's input:

(?:(?:(?P<hour>\d+):)?(?P<minute>\d{1,2}):)?(?P<second>\d{1,2})(?P<fraction>[,.]\d+)?

Expressed in Python, the floating-point representation gets computed as follows:

hour = int(m.group("hour")) if m.group("hour") else 0
minute = int(m.group("minute")) if m.group("minute") else 0
second = int(m.group("second")) if m.group("second") else 0
fraction = float("0" + m.group("fraction").replace(",", ".")) if m.group("fraction") else 0.0
result = (hour * 60 + minute) * 60 + second + fraction
Comment 1 Gabriel Barrantes 2024-04-05 23:56:27 UTC
*** Bug 21190 has been marked as a duplicate of this bug. ***