Optionally use UTC (rather than local) time on the HW clock

What features/apps/bugfixes needed in a future Puppy
Post Reply
Message
Author
User avatar
Pizzasgood
Posts: 6183
Joined: Wed 04 May 2005, 20:28
Location: Knoxville, TN, USA

Optionally use UTC (rather than local) time on the HW clock

#1 Post by Pizzasgood »

Puppy defaults to using localtime on the hardware clock. The reason for this is that the vast majority of desktop Windows installations use localtime on the hardware clock. But when a computer doesn't have Windows on it (as on my laptop and my old computer) or when the user just doesn't give a turkey about the Windows install (my new machine), keeping the hardware clock set to UTC time has some alluring benefits: If you properly configure Linux to use your local timezone (using the named options, like US/Eastern, rather than the numbered ones), it will automatically handle daylight savings time. You also don't have to correct the hardware clock's time when you move through timezones (like if you have a laptop). You just correct the timezone option, and Puppy will compute the proper time. Plus, it just feels cooler.

No, those aren't major things, but I'm very lazy.

Using UTC time is quite easy - set the hardware clock to UTC time, and then whenever you use the hwclock program to read or set it, add the --utc option instead of the --localtime option. There are only three places in Puppy where that command is used: /usr/sbin/timezone-set, /usr/sbin/set-time-for-puppy, and /etc/rc.d/rc.country.

Rather than hardcoding it, I figured it would be best to just make it optional, so weirdos like me can use UTC while everybody else can use local time. So what I did was add a file named /etc/clock, which sets the variable "$HWCLOCKTIME" to either 'localtime' or 'utc'. Then the three scripts listed above can just include /etc/clock and use the variable to set the time based on the user's choice.

The patch I provide here makes those changes. It defaults to using localtime, so you'll still have to edit /etc/clock if you want to switch it. The patch is applied by extracting it and then using the patch program with the -p 1 option in /. For example, if I downloaded the patch directly to /, I'd run these commands:

Code: Select all

cd /
gunzip optional_utc_time.patch.gz
patch -p 1 < optional_utc_time.patch
If applying this to an Unleashed tree, the package to be modified is 0rootfs_skeleton-XXX. Open a terminal inside the packages/0rootfs_skeleton-XXX/ directory and run the above commands (minus the cd one) providing the full path to the patch (unless you temporarily copy it into the 0rootfs_skeleton-XXX directory too, but if you do, be sure to remove it when you get done!).

That's the most reliable way to install these changes. Even if you've made other modifications to the three files it modifies, unless those changes interfere with the very few lines modified, they will be preserved.


If you want to know what exactly is changed, read the patch.

For those who don't know, a patch is simply the output of the "diff" command. They are human-readable. You just extract it and open it in Geany. Geany will even apply syntax highlighting. The lines to be added are in green and those to be removed are in read. (There is no concept of modifying a line - it is removed and replaced with the new line). So you can read them to find out what exactly is going to happen ahead of time.
Attachments
optional_utc_time.patch.gz
Provides an /etc/clock file which can be edited to specify whether Puppy should consider the
HW clock to be using utc or localtime. Modifies /usr/sbin/timezone-set,
/usr/sbin/set-time-for-puppy, and /etc/rc.d/rc.country.
(1.25 KiB) Downloaded 1309 times
[size=75]Between depriving a man of one hour from his life and depriving him of his life there exists only a difference of degree. --Muad'Dib[/size]
[img]http://www.browserloadofcoolness.com/sig.png[/img]

User avatar
lwill
Posts: 171
Joined: Fri 13 Jun 2008, 04:00
Location: City Of Lights
Contact:

#2 Post by lwill »

Very Cool! Now I don't screw up Fedora or Puppy when I switch back and forth.

One note though- I needed to install the devx_XXX.sfs which contains 'patch'

Lyle

User avatar
Pizzasgood
Posts: 6183
Joined: Wed 04 May 2005, 20:28
Location: Knoxville, TN, USA

#3 Post by Pizzasgood »

I forgot that Puppy doesn't have patch included in the actual ISO. For those who don't have a devx_xxx.sfs file, here are .pet packages of the modified files and /etc/clock, for 4.1.2 and 4.2.

EDIT: I've put together and uploaded a package for 4.3-pre-beta-reloaded. I have not actually tested that version because frankly I'm too tired and lazy to care right now. Should be fine though. Anyway, if it doesn't work, complain and I'll do it right.

Edit: spelling
Edit: added package for 4.3-pre-beta-reloaded
Attachments
optional_utc_time-430-pre-beta-reloaded.pet
Replaces /usr/sbin/timezone-set, /usr/sbin/set-time-for-puppy, and /etc/rc.d/rc.country, and adds /etc/clock.
(4.63 KiB) Downloaded 1193 times
optional_utc_time-412.pet
Replaces /usr/sbin/timezone-set, /usr/sbin/set-time-for-puppy, and /etc/rc.d/rc.country, and adds /etc/clock.
(4.21 KiB) Downloaded 1075 times
optional_utc_time-420.pet
Replaces /usr/sbin/timezone-set, /usr/sbin/set-time-for-puppy, and /etc/rc.d/rc.country, and adds /etc/clock.
(4.46 KiB) Downloaded 1213 times
Last edited by Pizzasgood on Mon 10 Aug 2009, 02:10, edited 2 times in total.
[size=75]Between depriving a man of one hour from his life and depriving him of his life there exists only a difference of degree. --Muad'Dib[/size]
[img]http://www.browserloadofcoolness.com/sig.png[/img]

User avatar
Pizzasgood
Posts: 6183
Joined: Wed 04 May 2005, 20:28
Location: Knoxville, TN, USA

#4 Post by Pizzasgood »

I guess I forgot to mention that this doesn't actually change your system over to using UTC. It adjusts the scripts to make them look at /etc/clock to find out what to use, but leaves it set to localtime.

If you want to actually use UTC time, you need to edit /etc/clock and change it from 'utc' to 'localtime'. Then the next time Puppy interacts with the hardware clock it will assume it uses UTC.

If your hardware clock was using localtime leading up to that, you'll also need to update it afterward. That can be done like this:
hwclock --systohc --utc

If your hardware clock was already using UTC but Puppy was using local and you just corrected Puppy, you can reload the time from the hardware clock like this:
hwclock --hctosys --utc


Alternately, in either of the above scenarios you could just go to "Menu->Desktop->Set date and time" and set the time.
[size=75]Between depriving a man of one hour from his life and depriving him of his life there exists only a difference of degree. --Muad'Dib[/size]
[img]http://www.browserloadofcoolness.com/sig.png[/img]

User avatar
Pizzasgood
Posts: 6183
Joined: Wed 04 May 2005, 20:28
Location: Knoxville, TN, USA

#5 Post by Pizzasgood »

I wrote a very simple GUI to help with changing from UTC to localtime or back. After letting you choose which one to use, it lets you either reload the software clock from the hardware clock, or reset the hardware clock from the software clock.

For tonight you just get raw code. I need to sleep. Tomorrow I'll polish it a little, test it harder, and then make a .pet of it.

Code: Select all

#!/bin/sh
. /etc/clock

if [ "$HWCLOCKTIME" = "utc" ]; then
    utc_flag='on'
    local_flag='off'
else
    utc_flag='off'
    local_flag='on'
fi

HWCLOCKTIME=$(Xdialog --radiolist "What should the hardware clock be interpreted as?" 0 0 0 localtime "" $local_flag utc "" $utc_flag 2>&1)

if [ "$HWCLOCKTIME" = "utc" ] || [ "$HWCLOCKTIME" = "localtime" ]; then
    sed -i "s/^HWCLOCKTIME=[^#]*/HWCLOCKTIME='$HWCLOCKTIME'/" /etc/clock

    RET=$(Xdialog --radiolist "Update the software clock or the hardware clock?" 0 0 0 software "to match hardware" on hardware "to match software" off 2>&1)

    if [ "$RET" = "software" ]; then
      hwclock --hctosys --$HWCLOCKTIME
    elif [ "$RET" = "hardware" ]; then
      hwclock --systohc --$HWCLOCKTIME
    fi

    Xdialog --infobox "Done" 0 0

fi
[size=75]Between depriving a man of one hour from his life and depriving him of his life there exists only a difference of degree. --Muad'Dib[/size]
[img]http://www.browserloadofcoolness.com/sig.png[/img]

User avatar
Pizzasgood
Posts: 6183
Joined: Wed 04 May 2005, 20:28
Location: Knoxville, TN, USA

#6 Post by Pizzasgood »

Okay, I made a couple slight improvements. I added a menu entry, the dialog boxes now have their titles set, and it is now tolerant of whether the /etc/clock file exists yet. I also made it handle aborting slightly more gracefully. Note: it never undoes anything. If you hit "cancel" that means you're canceling that step, not the previous ones. There are only two steps, so if you cancel the first one the program ends. If you cancel at the second one, the /etc/clock file will have been modified, but neither the hw clock nor the software clock will be modified.

And please note that this is useless without installing the patch or one of the .pet packages with the pre-modified scripts. Otherwise, this will create/edit the /etc/clock file, but Puppy will just ignore it.
Attachments
set_hwclock_type-0.1.pet
GUI for use with the above patch to choose which type of time the HW clock is assumed to be in, and to assist with either updating the HW clock or the software clock afterward.
(968 Bytes) Downloaded 1253 times
[size=75]Between depriving a man of one hour from his life and depriving him of his life there exists only a difference of degree. --Muad'Dib[/size]
[img]http://www.browserloadofcoolness.com/sig.png[/img]

iscraigh
Posts: 276
Joined: Sun 03 Sep 2006, 05:50

#7 Post by iscraigh »

Thank you this has been my biggest irritant with puppy. It works with upup 476

Craig

nanasy2
Posts: 2
Joined: Thu 29 Sep 2011, 08:49
Contact:

#8 Post by nanasy2 »

I've put together and uploaded a package for 4.3-pre-beta-reloaded. I have not actually tested that version because frankly I'm too tired and lazy to care right now. Should be fine though. Anyway, if it doesn't work, complain and I'll do it right.

Post Reply