[Nexus 5 Android Development] jeffsf:
Well, a week into my Nexus 5 and the dates on backups got to me. "Was that the one before or after I pooched my phone?"

I was doing rough conversions at first, then convinced myself that there was a reasonably fixed offset between "real time" and what TWRP was labeling things. [MENTION=1924950]helicopter88[/MENTION] let me know that there was a missing ability in the chip, so I looked for a run-time solution. Unfortunately, adjtimex wouldn't take a large enough offset.

Since the reasonably useless date stamps on backups were, well, reasonably useless, I did write a little script that converted the dates on the backups to something that matched my local time, given the offset.

Looks like [MENTION=912474]Dees_Troy[/MENTION] has saved me a bunch of coding inside TWRP as there is a going-forward fix in the TWRP sources now. Since he found the magic file where the offset is stored, you don't have to try to "guess" it from looking at your clock and your phone's (though $ date && adb shell date will get you the information you need).

For those backups you already have, here's how you can get the dates and times fixed up on them.

Edit -- Shell scripts made up for on-phone use:

sh birthday.sh while on the phone will give you offset and your phone's birthday (Yes, Korean time, of course!)

root@hammerhead:/ # sh /data/media/0/twrp-dates-tool/birthday.sh <
1386550085
Mon Dec 9 09:48:05 KST 2013

sh spew-twrp-rename.sh /path/to/TWRP/BACKUPS will write the commands to move the directories to the terminal (stdout)

The "spew" script finds the offset itself.

It will rewrite both old (20th century) dates and current ones, but only time-shift the older ones.

It will also convert spaces in the file names to underscore characters.

See attached files (.txt added to allow upload)

No, there isn't a "zip" for this -- checking that the right things are being done with your backups before they can't be undone is important

Read on only if you want to do this using perl.

Now, you can adb pull /data/system/time/ to get two files, ats_1 and ats_2 that have the offset in milliseconds as a 64-bit unsigned integer. Pick one or the other, get the human-readable output trim off the last three digits, and there is your offset (within a second). Mine drifts a second each week or so, but hey, this is a lot closer than 1970 something!

Once you have the offset, this script will take a list of files and spit out the commands to rename them, if they match a TWRP-format date in the 1970s. (Edit $offset to match yours.)

#!/usr/bin/perl

use strict;

use Date::Parse;
use Date::Format;

my $offset = 1386550084; # Edit this to match your offset

my $line;
my ($year,$mo,$day,$h,$m,$s);

my $twrp_time;
my $new_time_string;
my $before;
my $after;

LINE:
while ( defined ( $line = <> ) ) {

chomp $line; chomp $line;

next LINE unless $line =~ m/((197\d)-(\d\d)-(\d\d)--(\d\d)-(\d\d)-(\d\d))/;

$before = $`; $after = $';
$twrp_time = str2time("$2/$3/$4 $5:$6:$7 GMT");

$new_time_string = time2str("%Y-%m-%d_%H%M%S%z", $twrp_time + $offset);

$before =~ s/ /_/g;
$after =~ s/ /_/g;

print "mv '$line' ${before}${new_time_string}${after}\n";
}

Output looks like

mv '1970-02-22--23-02-13 omni_hammerhead-userdebug 4.4.2 KOT49H 128' 2014-01-30_155017-0800_omni_hammerhead-userdebug_4.4.2_KOT49H_128
mv '1970-02-23--13-50-29 omni_hammerhead-userdebug 4.4.2 KOT49H 128' 2014-01-31_063833-0800_omni_hammerhead-userdebug_4.4.2_KOT49H_128
mv '1970-02-23--15-22-06 omni_hammerhead-userdebug 4.4.2 KOT49H 126' 2014-01-31_081010-0800_omni_hammerhead-userdebug_4.4.2_KOT49H_126
mv '1970-02-23--16-10-01 omni_hammerhead-userdebug 4.4.2 KOT49H 126' 2014-01-31_085805-0800_omni_hammerhead-userdebug_4.4.2_KOT49H_126
mv '1970-02-25--17-11-08 omni_hammerhead-userdebug 4.4.2 KOT49H 127' 2014-02-02_095912-0800_omni_hammerhead-userdebug_4.4.2_KOT49H_127

which you can copy and paste into a shell on your device, or other places you have your TWRP backups backed up.

.