Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Proper handling of timezones

  • Loading branch information...
commit c547c011d66a66a96dbdd7ddda1a6db0dc53f76a 1 parent 1c466da
@nominolo nominolo authored
Showing with 25 additions and 4 deletions.
  1. +25 −4 darcs-to-git
View
29 darcs-to-git
@@ -11,7 +11,9 @@
require 'ostruct'
require 'rexml/document'
-ENV['TZ'] = 'GMT0'
+# Explicitly setting a time zone would cause darcs to only output in
+# that timezone hence we couldn't get the actual patch TZ
+# ENV['TZ'] = 'GMT0'
# GIT_DARCS_BRANCH = "darcs_repo" # name of the branch we import to
GIT_PATCHES = ".git/darcs_patches"
@@ -66,7 +68,8 @@ class DarcsPatch
def initialize(source_repo, patch_xml)
self.source_repo = source_repo
self.author = patch_xml.attribute('author').value
- self.date = darcs_date_to_git_date(patch_xml.attribute('date').to_s)
+ self.date = darcs_date_to_git_date(patch_xml.attribute('date').value,
+ patch_xml.attribute('local_date').value)
self.inverted = (patch_xml.attribute('inverted').to_s == 'True')
self.identifier = patch_xml.attribute('hash').to_s
self.name = patch_xml.get_elements('name').first.get_text.value rescue 'Unnamed patch'
@@ -178,8 +181,26 @@ class DarcsPatch
end
end
- def darcs_date_to_git_date(d)
- d.gsub(/^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)\d+$/, '\1-\2-\3 \4:\5')
+ def darcs_date_to_git_date(utc,local)
+ # We ignore the timezone name (it may be ambiguous) and instead
+ # calculate the timezone offset ourselves
+ if not utc =~ /^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/ then
+ raise "Wrong darcs date format"
+ end
+ utc_time = Time.utc($1,$2,$3,$4,$5,$6)
+ # darcs example: Mon Oct 2 14:23:28 CEST 2006
+ # everything except timezone name is fixed-length
+ # if parsing failes we just use UTC
+ if local =~ /^(\w\w\w) (\w\w\w) ([ 1-9]\d) ([ 0-9]\d)\:(\d\d)\:(\d\d) \w* (\d\d\d\d)/ then
+ local_time = Time.utc($7,$2,$3,$4,$5,$6)
+ else
+ local_time = utc_time
+ end
+ offs = local_time - utc_time
+ t = local_time
+ s = sprintf("%4d-%02d-%02d %02d:%02d:%02d %s%02d%02d", t.year, t.month, t.day,
+ t.hour, t.min, t.sec,
+ offs < 0 ? "-" : "+",offs.abs/3600,offs.abs.modulo(3600)/60 )
end
def git_ls_files(wanted)
Please sign in to comment.
Something went wrong with that request. Please try again.