zsh-workers
 help / color / mirror / code / Atom feed
* Missing "--" in the "age" function
@ 2013-05-21 11:53 Stephane Chazelas
  2013-05-21 15:19 ` Peter Stephenson
  0 siblings, 1 reply; 6+ messages in thread
From: Stephane Chazelas @ 2013-05-21 11:53 UTC (permalink / raw)
  To: zsh-workers

$ touch ./-s
$ autoload age
$ ls -ld -- *(e:age today:)
age:zstat:39: no files given
zsh: no matches found: *(e:age today:)

See patch below.

Also, the business about $1/$2 (not $AGEREF/$AGEREF2!) starting
with ":" to mean take the date (not time!) from reference files
seems not to be documented.

Cheers,
Stephane


--- /usr/share/zsh/functions/Calendar/age.back  2013-05-21 12:39:17.702739313 +0100
+++ /usr/share/zsh/functions/Calendar/age       2013-05-21 12:46:52.315052879 +0100
@@ -36,18 +36,18 @@
 local -a vals tmp

 [[ -e $REPLY ]] || return 1
-zstat -A vals +mtime $REPLY || return 1
+zstat -A vals +mtime -- $REPLY || return 1

 if (( $# >= 1 )); then
   if [[ $1 = :* ]]; then
-    zstat -A tmp -F "%Y/%m/%d" +mtime ${1[2,-1]} || return 1
+    zstat -A tmp -F "%Y/%m/%d" +mtime -- ${1#:} || return 1
     local AGEREF=$tmp[1]
   else
     local AGEREF=$1
   fi
   # if 1 argument given, never use globally defined AGEREF2
   if [[ $2 = :* ]]; then
-    zstat -A tmp -F "%Y/%m/%d" +mtime ${2[2,-1]} || return 1
+    zstat -A tmp -F "%Y/%m/%d" +mtime -- ${2#:} || return 1
     local AGEREF2=$tmp[1]
   else
     local AGEREF2=$2


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Missing "--" in the "age" function
  2013-05-21 11:53 Missing "--" in the "age" function Stephane Chazelas
@ 2013-05-21 15:19 ` Peter Stephenson
  2013-05-21 19:10   ` Stephane Chazelas
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Stephenson @ 2013-05-21 15:19 UTC (permalink / raw)
  To: zsh-workers

On Tue, 21 May 2013 12:53:32 +0100
Stephane Chazelas <stephane.chazelas@gmail.com> wrote:
> Also, the business about $1/$2 (not $AGEREF/$AGEREF2!) starting
> with ":" to mean take the date (not time!) from reference files
> seems not to be documented.

I can't remember if I meant people to use it, but I suppose I did.

diff --git a/Doc/Zsh/calsys.yo b/Doc/Zsh/calsys.yo
index 259eb23..b3eb454 100644
--- a/Doc/Zsh/calsys.yo
+++ b/Doc/Zsh/calsys.yo
@@ -651,16 +651,24 @@ date specification must be quoted to ensure tt(age) receives the correct
 arguments, hence the use of the additional colon to separate the date and
 time.
 
-example(AGEREF1=2006/10/04:10:15
+example(AGEREF=2006/10/04:10:15
 AGEREF2=2006/10/04:10:45
 print *+LPAR()PLUS()age+RPAR())
 
 This shows the same example before using another form of argument
-passing.  The dates and times in the parameters tt(AGEREF1) and tt(AGEREF2)
+passing.  The dates and times in the parameters tt(AGEREF) and tt(AGEREF2)
 stay in effect until unset, but will be overridden if any argument is
 passed as an explicit argument to age.  Any explicit argument
 causes both parameters to be ignored.
 
+Instead of an explicit date and time, it's possible to use the
+modification time of a file as the date and time for either argument
+by introducing the file name with a colon:
+
+example(print *+LPAR()e-age :file1 :file2-+RPAR())
+
+This matches all files modified no earlier than tt(file1) and
+no later than tt(file2).
 
 texinode(Calendar Styles)(Calendar Utility Functions)(Calendar System User Functions)(Calendar Function System)
 sect(Styles)
diff --git a/Functions/Calendar/age b/Functions/Calendar/age
index 2348da5..c636bdf 100644
--- a/Functions/Calendar/age
+++ b/Functions/Calendar/age
@@ -18,7 +18,7 @@
 # are allowed, but whitespace must be quoted to ensure age receives
 # the correct arguments.
 #
-#   AGEREF1=2006/10/04:10:15
+#   AGEREF=2006/10/04:10:15
 #   AGEREF2=2006/10/04:10:45
 #   print *(+age)
 #

pws


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Missing "--" in the "age" function
  2013-05-21 15:19 ` Peter Stephenson
@ 2013-05-21 19:10   ` Stephane Chazelas
  2013-05-22  8:46     ` Peter Stephenson
  0 siblings, 1 reply; 6+ messages in thread
From: Stephane Chazelas @ 2013-05-21 19:10 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-workers

2013-05-21 16:19:28 +0100, Peter Stephenson:
[...]

Thanks.

> +example(print *+LPAR()e-age :file1 :file2-+RPAR())
> +
> +This matches all files modified no earlier than tt(file1) and
> +no later than tt(file2).
[...]

In that case, shouldn't it be:

zstat -A tmp -F "%Y/%m/%d:%H:%M:%S"...

instead of 

zstat -A tmp -F "%Y/%m/%d"...

(and maybe say that sub-second granularity is not supported)

It would be nice to be able to use `age` for `atime` and `ctime`
as well.

-- 
Stephane


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Missing "--" in the "age" function
  2013-05-21 19:10   ` Stephane Chazelas
@ 2013-05-22  8:46     ` Peter Stephenson
  2013-05-22 19:21       ` Stephane Chazelas
  2013-05-22 20:00       ` Peter Stephenson
  0 siblings, 2 replies; 6+ messages in thread
From: Peter Stephenson @ 2013-05-22  8:46 UTC (permalink / raw)
  To: zsh-workers

On Tue, 21 May 2013 20:10:22 +0100
Stephane Chazelas <stephane.chazelas@gmail.com> wrote:
> 2013-05-21 16:19:28 +0100, Peter Stephenson:
> [...]
> 
> Thanks.
> 
> > +example(print *+LPAR()e-age :file1 :file2-+RPAR())
> > +
> > +This matches all files modified no earlier than tt(file1) and
> > +no later than tt(file2).
> [...]
> 
> In that case, shouldn't it be:
> 
> zstat -A tmp -F "%Y/%m/%d:%H:%M:%S"...
> 
> instead of 
> 
> zstat -A tmp -F "%Y/%m/%d"...

Hmm, it's a bit overloaded.  If you give an explicit date (just one),
you'd get files modified on that date; if you give a time as well the
start point moves up to that time; that's most useful with two arguments
to give a range.

Maybe the most convenient thing is if you give one :file argument it
uses the date, and if there is a second argument it uses the date and
time for both?

pws


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Missing "--" in the "age" function
  2013-05-22  8:46     ` Peter Stephenson
@ 2013-05-22 19:21       ` Stephane Chazelas
  2013-05-22 20:00       ` Peter Stephenson
  1 sibling, 0 replies; 6+ messages in thread
From: Stephane Chazelas @ 2013-05-22 19:21 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-workers

2013-05-22 09:46:01 +0100, Peter Stephenson:
[...]
> Maybe the most convenient thing is if you give one :file argument it
> uses the date, and if there is a second argument it uses the date and
> time for both?
[...]

makes sense. Maybe the two args file comparison should then be
implemented with [[ $REPLY -nt ${AGEREF#:} ]] so it works on
systems with sub-second mtime precision. (and allow the :file
syntax in $AGEREF as well, not only in "age" arguments).

-- 
Stephane


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Missing "--" in the "age" function
  2013-05-22  8:46     ` Peter Stephenson
  2013-05-22 19:21       ` Stephane Chazelas
@ 2013-05-22 20:00       ` Peter Stephenson
  1 sibling, 0 replies; 6+ messages in thread
From: Peter Stephenson @ 2013-05-22 20:00 UTC (permalink / raw)
  To: zsh-workers

On Wed, 22 May 2013 09:46:01 +0100
Peter Stephenson <p.stephenson@samsung.com> wrote:
> Maybe the most convenient thing is if you give one :file argument it
> uses the date, and if there is a second argument it uses the date and
> time for both?

diff --git a/Doc/Zsh/calsys.yo b/Doc/Zsh/calsys.yo
index b3eb454..7dc51ab 100644
--- a/Doc/Zsh/calsys.yo
+++ b/Doc/Zsh/calsys.yo
@@ -665,10 +665,15 @@ Instead of an explicit date and time, it's possible to use the
 modification time of a file as the date and time for either argument
 by introducing the file name with a colon:
 
+example(print *+LPAR()e-age :file1-+RPAR())
+
+matches all files created on the same day (24 hours starting from
+midnight) as tt(file1).
+
 example(print *+LPAR()e-age :file1 :file2-+RPAR())
 
-This matches all files modified no earlier than tt(file1) and
-no later than tt(file2).
+matches all files modified no earlier than tt(file1) and
+no later than tt(file2); precision here is to the nearest second.
 
 texinode(Calendar Styles)(Calendar Utility Functions)(Calendar System User Functions)(Calendar Function System)
 sect(Styles)
diff --git a/Functions/Calendar/age b/Functions/Calendar/age
index c636bdf..17cf4d1 100644
--- a/Functions/Calendar/age
+++ b/Functions/Calendar/age
@@ -33,6 +33,7 @@ zmodload -i zsh/parameter
 
 autoload -Uz calendar_scandate
 
+local timefmt
 local -a vals tmp
 
 [[ -e $REPLY ]] || return 1
@@ -40,14 +41,19 @@ zstat -A vals +mtime -- $REPLY || return 1
 
 if (( $# >= 1 )); then
   if [[ $1 = :* ]]; then
-    zstat -A tmp -F "%Y/%m/%d" +mtime -- ${1#:} || return 1
+      if (( $# > 1 )); then
+	  timefmt="%Y/%m/%d:%H:%M:%S"
+      else
+	  timefmt="%Y/%m/%d"
+      fi
+      zstat -A tmp -F $timefmt +mtime -- ${1#:} || return 1
     local AGEREF=$tmp[1]
   else
     local AGEREF=$1
   fi
   # if 1 argument given, never use globally defined AGEREF2
   if [[ $2 = :* ]]; then
-    zstat -A tmp -F "%Y/%m/%d" +mtime -- ${2#:} || return 1
+    zstat -A tmp -F "%Y/%m/%d:%H:%M:%S" +mtime -- ${2#:} || return 1
     local AGEREF2=$tmp[1]
   else
     local AGEREF2=$2

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-05-22 22:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-21 11:53 Missing "--" in the "age" function Stephane Chazelas
2013-05-21 15:19 ` Peter Stephenson
2013-05-21 19:10   ` Stephane Chazelas
2013-05-22  8:46     ` Peter Stephenson
2013-05-22 19:21       ` Stephane Chazelas
2013-05-22 20:00       ` Peter Stephenson

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).