about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2009-09-11 11:20:45 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2009-09-11 11:20:45 +0000
commit49b4a710090cb312e8c70dc13966790c82abaab0 (patch)
tree9c99f0748c0054883cf3f003a4d96afc4f9548a4
parent12dfec77e9d939712fcb5bafa6310bd8aae774d6 (diff)
downloadzsh-49b4a710090cb312e8c70dc13966790c82abaab0.tar.gz
zsh-49b4a710090cb312e8c70dc13966790c82abaab0.tar.xz
zsh-49b4a710090cb312e8c70dc13966790c82abaab0.zip
Baptiste Daroussin: 27267 plus 27269 plus doc:
remove perl dependency
-rw-r--r--ChangeLog8
-rw-r--r--Doc/Zsh/zftpsys.yo11
-rw-r--r--Functions/Zftp/zfrtime46
3 files changed, 33 insertions, 32 deletions
diff --git a/ChangeLog b/ChangeLog
index d1fdb115d..b628c065f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2009-09-11  Peter Stephenson  <pws@csr.com>
+
+	* Baptiste Daroussin: 27267 plus 27269 plus doc:
+	Functions/Zftp/zfrtime, Doc/Zsh/zftpsys.yo: remove perl
+	dependency.
+
 2009-09-10  Peter Stephenson  <pws@csr.com>
 
 	* Greg Klanderman: 27259 / 27260:
@@ -12146,5 +12152,5 @@
 
 *****************************************************
 * This is used by the shell to define $ZSH_PATCHLEVEL
-* $Revision: 1.4773 $
+* $Revision: 1.4774 $
 *****************************************************
diff --git a/Doc/Zsh/zftpsys.yo b/Doc/Zsh/zftpsys.yo
index 627e0582d..56308302c 100644
--- a/Doc/Zsh/zftpsys.yo
+++ b/Doc/Zsh/zftpsys.yo
@@ -220,8 +220,7 @@ The commands for retrieving files all take at least two options. tt(-G)
 suppresses remote filename expansion which would otherwise be performed
 (see below for a more detailed description of that).  tt(-t) attempts
 to set the modification time of the local file to that of the remote file:
-this requires version 5 of tt(perl), see the description of the function
-tt(zfrtime) below for more information.
+see the description of the function tt(zfrtime) below for more information.
 
 startitem()
 findex(zfget)
@@ -462,11 +461,9 @@ findex(zfrtime)
 item(tt(zfrtime var(lfile) var(rfile) [ var(time) ]))(
 Set the local file var(lfile) to have the same modification time as the
 remote file var(rfile), or the explicit time var(time) in FTP format
-tt(CCYYMMDDhhmmSS) for the GMT timezone.
-
-Currently this requires tt(perl) version 5 to perform the conversion from
-GMT to local time.  This is unfortunately difficult to do using shell code
-alone.
+tt(CCYYMMDDhhmmSS) for the GMT timezone.  This uses the shell's
+tt(zsh/datetime) module to perform the conversion from
+GMT to local time.
 )
 findex(zftp_chpwd, supplied version)
 item(tt(zftp_chpwd))(
diff --git a/Functions/Zftp/zfrtime b/Functions/Zftp/zfrtime
index f63ffe04b..b1653d615 100644
--- a/Functions/Zftp/zfrtime
+++ b/Functions/Zftp/zfrtime
@@ -6,12 +6,13 @@
 #
 # Unfortunately, since the time returned from FTP is GMT and
 # your file needs to be set in local time, we need to do some
-# hacking around with time.  At the moment this requires perl 5
-# with the standard library.
+# hacking around with time.
 
 emulate -L zsh
+zmodload zsh/datetime
 
-local time gmtime loctime
+local time gmtime loctime year mon mday hr min sec y tmpdate
+local -i days_since_epoch
 
 if [[ -n $3 ]]; then
   time=$3
@@ -21,25 +22,22 @@ else
 fi
 [[ -z $time ]] && return 1
 
-# Now's the real *!@**!?!.  We have the date in GMT and want to turn
-# it into local time for touch to handle.  It's just too nasty
-# to handle in zsh; do it in perl.
-if perl -mTime::Local -e '($file, $t) = @ARGV;
-$yr = substr($t, 0, 4) - 1900;
-$mon = substr($t, 4, 2) - 1;
-$mday = substr($t, 6, 2) + 0;
-$hr = substr($t, 8, 2) + 0;
-$min = substr($t, 10, 2) + 0;
-$sec = substr($t, 12, 2) + 0;
-$time = Time::Local::timegm($sec, $min, $hr, $mday, $mon, $yr);
-utime $time, $time, $file and return 0;' $1 $time 2>/dev/null; then
-  print "Setting time for $1 failed.  Need perl 5." 2>1
-fi
-
-# If it wasn't for the GMT/local time thing, it would be this simple.
-#
-# time="${time[1,12]}.${time[13,14]}"
-#
-# touch -t $time $1
+year=$time[1,4]
+mon=$time[5,6]
+mday=$time[7,8]
+hr=$time[9,10]
+min=$time[11,12]
+sec=$time[13,14]
 
-# }
+#count the number of days since epoch without the current day
+for y  in {1970..$(( $year - 1))}; do
+  strftime -s tmpdate -r "%Y/%m/%d" ${y}/12/31
+  days_since_epoch+=$(strftime "%j" $tmpdate)
+done
+strftime -s tmpdate -r "%Y/%m/%d" $year/$mon/$(( $mday - 1 ))
+days_since_epoch+=$(strftime "%j" $tmpdate)
+# convert the time in number of seconds (this should be equivalent to timegm)
+time=$(( $sec + 60 * ( $min + 60 * ($hr + 24 * $days_since_epoch))  ))
+#Convert it back to CCYYMMDDhhmmSS
+strftime -s time "%Y%m%d%H%M%S" ${EPOCHSECONDS}
+touch -t ${time[1,12]}.${time[13,14]} $1