zsh-workers
 help / color / mirror / code / Atom feed
be95c4316bea5adb09d444ba6e1a87b880d52d4a blob 1416 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 
# function zfrtime {
# Set the modification time of file LOCAL to that of REMOTE.
# If the optional TIME is passed, it should be in the FTP format
# CCYYMMDDhhmmSS, i.e. no dot before the seconds, and in GMT.
# This is what both `zftp remote' and `zftp local' return.
#
# 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.

emulate -L zsh
zmodload zsh/datetime

local time gmtime loctime year mon mday hr min sec y tmpdate
local -i days_since_epoch

if [[ -n $3 ]]; then
  time=$3
else
  time=($(zftp remote $2 2>/dev/null))
  [[ -n $time ]] && time=$time[2]
fi
[[ -z $time ]] && return 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 ({1970..$(( $year - 1))}){ strftime -s tmpdate -r "%Y/%m/%d" ${y}/12/31; days_since_epoch+=$(strftime "%j" $tmpdate) }
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
debug log:

solving be95c43 ...
found be95c43 in https://inbox.vuxu.org/zsh-workers/ed7b1c610909110337g30525e9bxdd5b4146a17f3a@mail.gmail.com/
found f63ffe0 in https://git.vuxu.org/mirror/zsh/
preparing index
index prepared:
100644 f63ffe04bd8dfe9e8f5f455c2a2496119380d4fa	Functions/Zftp/zfrtime

applying [1/1] https://inbox.vuxu.org/zsh-workers/ed7b1c610909110337g30525e9bxdd5b4146a17f3a@mail.gmail.com/
diff --git a/Functions/Zftp/zfrtime b/Functions/Zftp/zfrtime
index f63ffe0..be95c43 100644

Checking patch Functions/Zftp/zfrtime...
Applied patch Functions/Zftp/zfrtime cleanly.

index at:
100644 be95c4316bea5adb09d444ba6e1a87b880d52d4a	Functions/Zftp/zfrtime

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).