feature suggestion - add an option to set the time when day starts

Asked by Edgar Maloverian

Use case:I want to avoid temptation for my kids to use tomorrow's time before sleep after the midnight. Logical would be to reset daily limit at some time that's guaranteed sleep, like 5 AM, but this feature is missing.

Question information

Language:
English Edit question
Status:
Answered
For:
Timekpr-nExT Edit question
Assignee:
Eduards Bezverhijs Edit question
Last query:
Last reply:
Revision history for this message
Eduards Bezverhijs (mjasnik) said :
#1

Hi, I think Timekpr-nExT already has this feature, configure day intervals for every day from 9:00 to 23:00 or whichever hours you think he can start / finish using the computer and you're set.
Let me know whether this helps.

Revision history for this message
Edgar Maloverian (ets-o) said :
#2

Sorry, I probably did not word my question properly.
 If I was able to set time period to 5AM-3AM(next day) that would be the feature I am talking about.

Revision history for this message
Eduards Bezverhijs (mjasnik) said :
#3

Now I'm confused :)

From the last comment I understand that you want to allow to use a computer from 5 in the morning (night) until the 3 in the morning (night) next day?

If I didn't understand that properly, can you please write what is the current limit per day for the user and what hours use can work and what hours are guaranteed sleep hours.

Example: user has daily limit of 6 hrs, he can work on computer from 9:00 in the morning until 1:00 in the morning next day, then they must go to sleep until 9:00 in the morning again. In this example I understand that you do not want user to spend that one hour at next days limit expense, but rather use spare time left from previous day, of course, if he has some left. Is that so?

As time reset at any other time than midnight is not daily limit anymore and that might be problematic, I'm trying to understand whether your use case can be implemented by tweaking current configuration.

Revision history for this message
Edgar Maloverian (ets-o) said :
#4

Firstly thank you for your attention to that really minor convenience feature for really great product that beats most commercial parental controls :)

I think best way to explain the the problem is to have real life scenario:

let's say my kid has 4 hour daily limit and no strict bedtime.
if at 23:30 she has 45 minutes left, she will be logged out at 4 AM, while with desired feature would be to log her out at 00:15 :)

You can think of it as a weekly limit could be for a week starting either on Sunday or Monday, depending on country.

(I imagine that's not worth doing it, as probably code is stuffed with date comparisons, but definitely useful feature once/if you will create similar new software. )

Thanks again and feel free to close :-)

Revision history for this message
Eduards Bezverhijs (mjasnik) said :
#5

Yeah, this enhancement would be problematic currently.

Revision history for this message
Eduards Bezverhijs (mjasnik) said :
#6

.

Revision history for this message
Andreas Rappold (nedbes) said :
#7

Hi, I was wondering the same thing and found this question.

There is a "workaround" I'm currently testing: patch `datetime.datetime.now` to return the current time with a specific offset. This is usually a bad idea, but given the effort required to provide this feature, it might serve a purpose here.

```diff
diff --git a/client/timekpra.py b/client/timekpra.py
index 18e3cb1..7d06655 100644
--- a/client/timekpra.py
+++ b/client/timekpra.py
@@ -13,6 +13,7 @@ if "/usr/lib/python3/dist-packages" not in sys.path:
     sys.path.append("/usr/lib/python3/dist-packages")

 # timekpr imports
+import timekpr.retime
 from timekpr.client.admin.adminprocessor import timekprAdminClient
 from timekpr.common.utils import misc

diff --git a/client/timekprc.py b/client/timekprc.py
index 35fb55c..58399b4 100644
--- a/client/timekprc.py
+++ b/client/timekprc.py
@@ -13,6 +13,7 @@ if "/usr/lib/python3/dist-packages" not in sys.path:
     sys.path.append("/usr/lib/python3/dist-packages")

 # timekpr imports
+import timekpr.retime
 from timekpr.client.interface.dbus.daemon import timekprClient
 from timekpr.common.utils import misc

diff --git a/resource/launchers/timekpr-admin-su.desktop b/resource/launchers/timekpr-admin-su.desktop
index df7f00d..3e38543 100644
--- a/resource/launchers/timekpr-admin-su.desktop
+++ b/resource/launchers/timekpr-admin-su.desktop
@@ -10,7 +10,7 @@ Comment[de]=Kontrolle der Computernutzung
 Comment[fr]=Gardez le contrôle de l'utilisation de l'ordinateur
 Comment[it]=Mantieni il controllo sull'utilizzo del computer
 Comment[lv]=Uzturēt kontroli pār datora lietošanu
-Exec=pkexec /usr/bin/timekpra
+Exec=pkexec env DELTA_SECONDS=-3600 /usr/bin/timekpra
 Icon=timekpr
 Terminal=false
 Type=Application
diff --git a/resource/launchers/timekpr-admin.desktop b/resource/launchers/timekpr-admin.desktop
index f32ca1c..08f0dad 100644
--- a/resource/launchers/timekpr-admin.desktop
+++ b/resource/launchers/timekpr-admin.desktop
@@ -10,7 +10,7 @@ Comment[de]=Kontrolle der Computernutzung
 Comment[fr]=Gardez le contrôle de l'utilisation de l'ordinateur
 Comment[it]=Mantieni il controllo sull'utilizzo del computer
 Comment[lv]=Uzturēt kontroli pār datora lietošanu
-Exec=/usr/bin/timekpra
+Exec=env DELTA_SECONDS=-3600 /usr/bin/timekpra
 Icon=timekpr
 Terminal=false
 Type=Application
diff --git a/resource/launchers/timekpr-client.desktop b/resource/launchers/timekpr-client.desktop
index bd5c81e..ed4caee 100644
--- a/resource/launchers/timekpr-client.desktop
+++ b/resource/launchers/timekpr-client.desktop
@@ -10,7 +10,7 @@ Comment[de]=Kontrolle der Computernutzung
 Comment[fr]=Gardez le contrôle de l'utilisation de l'ordinateur
 Comment[it]=Mantieni il controllo sull'utilizzo del computer
 Comment[lv]=Uzturēt kontroli pār datora lietošanu
-Exec=/usr/bin/timekprc
+Exec=env DELTA_SECONDS=-3600 /usr/bin/timekprc
 Icon=timekpr-client
 Terminal=false
 Type=Application
diff --git a/resource/server/systemd/timekpr.service b/resource/server/systemd/timekpr.service
index bbf0d69..f549388 100644
--- a/resource/server/systemd/timekpr.service
+++ b/resource/server/systemd/timekpr.service
@@ -7,6 +7,7 @@ After=multi-user.target
 Type=simple
 User=root
 WorkingDirectory=/usr/lib/python3/dist-packages/timekpr/
+Environment=DELTA_SECONDS=-3600
 ExecStart=/usr/bin/timekprd
 StandardOutput=syslog
 StandardError=syslog
diff --git a/retime.py b/retime.py
new file mode 100644
index 0000000..46015e5
--- /dev/null
+++ b/retime.py
@@ -0,0 +1,31 @@
+import datetime
+import os
+import sys
+
+
+_TIME_DELTA = datetime.timedelta(seconds=float(os.environ["DELTA_SECONDS"]))
+
+
+class _Module:
+ def __init__(self):
+ self.datetime = _Datetime
+
+ def __getattr__(self, name):
+ return getattr(datetime, name)
+
+
+class _Datetime_type(type):
+ def __getattr__(self, name):
+ return getattr(datetime.datetime, name)
+
+
+class _Datetime(metaclass=_Datetime_type):
+ def __new__(cls, *args, **kwargs):
+ return datetime.datetime.__new__(datetime.datetime, *args, **kwargs)
+
+ @staticmethod
+ def now():
+ return datetime.datetime.now() + _TIME_DELTA
+
+
+sys.modules["datetime"] = _Module()
diff --git a/server/timekprd.py b/server/timekprd.py
index 3630b36..0561075 100644
--- a/server/timekprd.py
+++ b/server/timekprd.py
@@ -26,6 +26,7 @@ if "/usr/lib/python3/dist-packages" not in sys.path:
 import signal

 # timekpr imports
+import timekpr.retime
 from timekpr.common.constants import constants as cons
 from timekpr.common.log import log
 from timekpr.server.interface.dbus.daemon import timekprDaemon
```

This adds `retime.py` which replaces `datetime` using a lot of Python magic, and changes the desktop and service files to shift time by 1h.

Revision history for this message
Andreas Rappold (nedbes) said :
#8

Fyi I didn't experience any issues so far with the expected result ("midnight" at 01:00). In the meantime I realized that it is sufficient to set the environment variable TZ, e.g. TZ=UTC+4. With the same caveats: you need to keep the timezone difference in mind when setting times.

Can you help with this problem?

Provide an answer of your own, or ask Edgar Maloverian for more information if necessary.

To post a message you must log in.