* How to compare time of last file modification? @ 2012-07-01 0:38 Thorsten Jolitz 2012-07-01 0:41 ` Thorsten Jolitz 0 siblings, 1 reply; 11+ messages in thread From: Thorsten Jolitz @ 2012-07-01 0:38 UTC (permalink / raw) To: help-gnu-emacs Hi List, the Elisp manual tells me about file-attributes: 4. The time of last access, as a list of two integers. The first integer has the high-order 16 bits of time, the second has the low 16 bits. (This is similar to the value of current-time; see Time of Day.) Note that on some FAT-based filesystems, only the date of last access is recorded, so this time will always hold the midnight of the day of last access. 5. The time of last modification as a list of two integers (as above). This is the last time when the file's contents were modified. If I want to compare the time of last modification of two files - how do I do that, using these two integers? -- cheers, Thorsten ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: How to compare time of last file modification? 2012-07-01 0:38 How to compare time of last file modification? Thorsten Jolitz @ 2012-07-01 0:41 ` Thorsten Jolitz 0 siblings, 0 replies; 11+ messages in thread From: Thorsten Jolitz @ 2012-07-01 0:41 UTC (permalink / raw) To: help-gnu-emacs Thorsten Jolitz <tjolitz@googlemail.com> writes: > Hi List, > the Elisp manual tells me about file-attributes: > > > 4. The time of last access, as a list of two integers. The > first integer has the high-order 16 bits of time, the > second has the low 16 bits. (This is similar to the value > of current-time; see Time of Day.) Note that on some > FAT-based filesystems, only the date of last access is > recorded, so this time will always hold the midnight of the > day of last access. > > 5. The time of last modification as a list of two integers (as > above). This is the last time when the file's contents were > modified. > > > If I want to compare the time of last modification of two files - how do > I do that, using these two integers? Ups, I just found the function 'file-newer-than-file-p' that solves my problem. Sorry for the noise. -- cheers, Thorsten ^ permalink raw reply [flat|nested] 11+ messages in thread
[parent not found: <mailman.3790.1341102956.855.help-gnu-emacs@gnu.org>]
* Re: How to compare time of last file modification? [not found] <mailman.3790.1341102956.855.help-gnu-emacs@gnu.org> @ 2012-07-01 1:16 ` Pascal J. Bourguignon 2012-07-01 8:56 ` Thorsten Jolitz 2012-07-01 9:23 ` Michael Albinus 2012-07-01 10:13 ` Lars Magne Ingebrigtsen 1 sibling, 2 replies; 11+ messages in thread From: Pascal J. Bourguignon @ 2012-07-01 1:16 UTC (permalink / raw) To: help-gnu-emacs Thorsten Jolitz <tjolitz@googlemail.com> writes: > Hi List, > the Elisp manual tells me about file-attributes: > > > 4. The time of last access, as a list of two integers. The > first integer has the high-order 16 bits of time, the > second has the low 16 bits. (This is similar to the value > of current-time; see Time of Day.) Note that on some > FAT-based filesystems, only the date of last access is > recorded, so this time will always hold the midnight of the > day of last access. > > 5. The time of last modification as a list of two integers (as > above). This is the last time when the file's contents were > modified. > > > If I want to compare the time of last modification of two files - how do > I do that, using these two integers? You have to apply some powerful magic, called "maths". If I were you, I'd not read the following of that message, it's much too esoteric. The first time is characterized with this system of equations: t₁ = 65536×h₁ + l₁ 0 ≤ h₁ < 65536 0 ≤ l₁ < 65536 The second time with this similar system: t₂ = 65536×h₂ + l₂ 0 ≤ h₂ < 65536 0 ≤ l₂ < 65536 Comparing those times is adding this equation to the above system: t₁ < t₂ t₁ = 65536×h₁ + l₁ 0 ≤ h₁ < 65536 0 ≤ l₁ < 65536 t₂ = 65536×h₂ + l₂ 0 ≤ h₂ < 65536 0 ≤ l₂ < 65536 So we have to solve a system of equations with 3 variables and 7 equations. I told you do not read further! t₁ < t₂ ∧ t₁ = 65536×h₁ + l₁ ∧ t₂ = 65536×h₂ + l₂ ⇔ 65536×h₁+l₁ < 65536×h₂+l₂ ∧ t₁ = 65536×h₁ + l₁ ∧ t₂ = 65536×h₂ + l₂ Now, notice that: ∀n, 65536×(n+1) + 0 > 65536×n + 65535 ⇔ ∀n, 65536×n + 65536 > 65536×n + 65535 ⇔ ∀n, 65536 > 65535 ⇔ true Similarly, ∀n,p n > p ⇒ 65536×n + 0 > 65536×p + 65535 ⇔ ∀n,p n > p ⇒ 65536×(n-p+p) > 65536×p + 65535 ⇔ ∀n,p n > p ⇒ 65536×(n-p)+65536×p > 65536×p + 65535 ⇔ ∀n,p n > p ⇒ 65536×(n-p) > 65535 ⇔ ∀n,p n > p ⇒ 65536×(n-p) ≥ 65536 > 65535 ⇔ ∀n,p n > p ⇒ true ⇔ true Therefore, if h₂ > h₁ then t₂ > t₁ and if h₁ > h₂ then t₁ > t₂ Now, if h₂ = h₁, then t₁ < t₂ ∧ t₁ = 65536×h₁ + l₁ ∧ t₂ = 65536×h₂ + l₂ ∧ h₁ = h₂ ⇔ 65536×h₁+l₁ < 65536×h₁+l₂ ∧ t₁ = 65536×h₁ + l₁ ∧ t₂ = 65536×h₂ + l₂ ∧ h₁ = h₂ ⇔ l₁ < l₂ ∧ t₁ = 65536×h₁ + l₁ ∧ t₂ = 65536×h₂ + l₂ ∧ h₁ = h₂ Therefore, if h₂ > h₁ then t₂ > t₁ if h₁ > h₂ then t₁ > t₂ if h₁ = h₂ then if l₁ < l₂ then t₁ < t₂ if l₁ > l₂ then t₁ > t₂ if l₁ = l₂ then t₁ = t₂ Does this look like an "algorithms"? I told you, dark magic here! (defun time-lessp (t1 t2) "Returns whether t1<t2 t1 and t2 are lists of two integers. The first integer has the high-order 16 bits of time, the second has the low 16 bits." (destructuring-bind (h1 l1) t1 (destructuring-bind (h2 l2) t2 (cond ((< h1 h2) t) ((> h1 h2) nil) (t (cond ((< l1 l2) t) (t nil))))))) -- __Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: How to compare time of last file modification? 2012-07-01 1:16 ` Pascal J. Bourguignon @ 2012-07-01 8:56 ` Thorsten Jolitz 2012-07-01 9:23 ` Michael Albinus 1 sibling, 0 replies; 11+ messages in thread From: Thorsten Jolitz @ 2012-07-01 8:56 UTC (permalink / raw) To: help-gnu-emacs "Pascal J. Bourguignon" <pjb@informatimago.com> writes: > Thorsten Jolitz <tjolitz@googlemail.com> writes: > >> Hi List, >> the Elisp manual tells me about file-attributes: >> >> >> 4. The time of last access, as a list of two integers. The >> first integer has the high-order 16 bits of time, the >> second has the low 16 bits. (This is similar to the value >> of current-time; see Time of Day.) Note that on some >> FAT-based filesystems, only the date of last access is >> recorded, so this time will always hold the midnight of the >> day of last access. >> >> 5. The time of last modification as a list of two integers (as >> above). This is the last time when the file's contents were >> modified. >> >> >> If I want to compare the time of last modification of two files - how do >> I do that, using these two integers? > > You have to apply some powerful magic, called "maths". > > If I were you, I'd not read the following of that message, it's much too > esoteric. > > > > The first time is characterized with this system of equations: > > t₁ = 65536×h₁ + l₁ > 0 ≤ h₁ < 65536 > 0 ≤ l₁ < 65536 > > The second time with this similar system: > > t₂ = 65536×h₂ + l₂ > 0 ≤ h₂ < 65536 > 0 ≤ l₂ < 65536 > > > Comparing those times is adding this equation to the above system: > > t₁ < t₂ > t₁ = 65536×h₁ + l₁ > 0 ≤ h₁ < 65536 > 0 ≤ l₁ < 65536 > t₂ = 65536×h₂ + l₂ > 0 ≤ h₂ < 65536 > 0 ≤ l₂ < 65536 > > So we have to solve a system of equations with 3 variables and 7 > equations. > > I told you do not read further! > > > t₁ < t₂ ∧ t₁ = 65536×h₁ + l₁ ∧ t₂ = 65536×h₂ + l₂ > ⇔ 65536×h₁+l₁ < 65536×h₂+l₂ ∧ t₁ = 65536×h₁ + l₁ ∧ t₂ = 65536×h₂ + l₂ > > > Now, notice that: > > ∀n, 65536×(n+1) + 0 > 65536×n + 65535 > ⇔ ∀n, 65536×n + 65536 > 65536×n + 65535 > ⇔ ∀n, 65536 > 65535 > ⇔ true > > Similarly, > > ∀n,p n > p ⇒ 65536×n + 0 > 65536×p + 65535 > ⇔ ∀n,p n > p ⇒ 65536×(n-p+p) > 65536×p + 65535 > ⇔ ∀n,p n > p ⇒ 65536×(n-p)+65536×p > 65536×p + 65535 > ⇔ ∀n,p n > p ⇒ 65536×(n-p) > 65535 > ⇔ ∀n,p n > p ⇒ 65536×(n-p) ≥ 65536 > 65535 > ⇔ ∀n,p n > p ⇒ true > ⇔ true > > Therefore, if h₂ > h₁ then t₂ > t₁ > and if h₁ > h₂ then t₁ > t₂ > > Now, if h₂ = h₁, then > > t₁ < t₂ ∧ t₁ = 65536×h₁ + l₁ ∧ t₂ = 65536×h₂ + l₂ ∧ h₁ = h₂ > > ⇔ 65536×h₁+l₁ < 65536×h₁+l₂ ∧ t₁ = 65536×h₁ + l₁ > ∧ t₂ = 65536×h₂ + l₂ ∧ h₁ = h₂ > > ⇔ l₁ < l₂ ∧ t₁ = 65536×h₁ + l₁ ∧ t₂ = 65536×h₂ + l₂ ∧ h₁ = h₂ > > > Therefore, if h₂ > h₁ then t₂ > t₁ > if h₁ > h₂ then t₁ > t₂ > if h₁ = h₂ then if l₁ < l₂ then t₁ < t₂ > if l₁ > l₂ then t₁ > t₂ > if l₁ = l₂ then t₁ = t₂ > > Does this look like an "algorithms"? I told you, dark magic here! > > > (defun time-lessp (t1 t2) > "Returns whether t1<t2 > t1 and t2 are lists of two integers. The first integer has the > high-order 16 bits of time, the second has the low 16 bits." > (destructuring-bind (h1 l1) t1 > (destructuring-bind (h2 l2) t2 > (cond > ((< h1 h2) t) > ((> h1 h2) nil) > (t (cond ((< l1 l2) t) > (t nil))))))) I knew there is a simple and intuitive solution ;) While the math part does look a bit esoteric, your function is similar to what I would have expected as a solution. But I wasn't really sure how to interpret these integers, and probably would have needed much more lines of code myself to write something similar. Thank you. -- cheers, Thorsten ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: How to compare time of last file modification? 2012-07-01 1:16 ` Pascal J. Bourguignon 2012-07-01 8:56 ` Thorsten Jolitz @ 2012-07-01 9:23 ` Michael Albinus 1 sibling, 0 replies; 11+ messages in thread From: Michael Albinus @ 2012-07-01 9:23 UTC (permalink / raw) To: Pascal J. Bourguignon; +Cc: help-gnu-emacs "Pascal J. Bourguignon" <pjb@informatimago.com> writes: > (defun time-lessp (t1 t2) > "Returns whether t1<t2 > t1 and t2 are lists of two integers. The first integer has the > high-order 16 bits of time, the second has the low 16 bits." > (destructuring-bind (h1 l1) t1 > (destructuring-bind (h2 l2) t2 > (cond > ((< h1 h2) t) > ((> h1 h2) nil) > (t (cond ((< l1 l2) t) > (t nil))))))) In Tramp, we use (defun tramp-time-less-p (t1 t2) "Say whether time value T1 is less than time value T2." (unless t1 (setq t1 '(0 0))) (unless t2 (setq t2 '(0 0))) (or (< (car t1) (car t2)) (and (= (car t1) (car t2)) (< (nth 1 t1) (nth 1 t2))))) Best regards, Michael. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: How to compare time of last file modification? [not found] <mailman.3790.1341102956.855.help-gnu-emacs@gnu.org> 2012-07-01 1:16 ` Pascal J. Bourguignon @ 2012-07-01 10:13 ` Lars Magne Ingebrigtsen 2012-07-01 17:26 ` Thorsten Jolitz [not found] ` <mailman.3833.1341163416.855.help-gnu-emacs@gnu.org> 1 sibling, 2 replies; 11+ messages in thread From: Lars Magne Ingebrigtsen @ 2012-07-01 10:13 UTC (permalink / raw) To: Thorsten Jolitz; +Cc: help-gnu-emacs Thorsten Jolitz <tjolitz@googlemail.com> writes: > If I want to compare the time of last modification of two files - how do > I do that, using these two integers? Use `time-less-p': time-less-p is a compiled Lisp function in `time-date.el'. (time-less-p T1 T2) Return non-nil if time value T1 is earlier than time value T2. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog http://lars.ingebrigtsen.no/ ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: How to compare time of last file modification? 2012-07-01 10:13 ` Lars Magne Ingebrigtsen @ 2012-07-01 17:26 ` Thorsten Jolitz [not found] ` <mailman.3833.1341163416.855.help-gnu-emacs@gnu.org> 1 sibling, 0 replies; 11+ messages in thread From: Thorsten Jolitz @ 2012-07-01 17:26 UTC (permalink / raw) To: help-gnu-emacs Lars Magne Ingebrigtsen <lmi@gnus.org> writes: > Thorsten Jolitz <tjolitz@googlemail.com> writes: > >> If I want to compare the time of last modification of two files - how do >> I do that, using these two integers? > > Use `time-less-p': > > time-less-p is a compiled Lisp function in `time-date.el'. > > (time-less-p T1 T2) > > Return non-nil if time value T1 is earlier than time value T2. Thanks to everybody for several solutions. Is there a reason to prefer time-less-p or the custom-made solutions over file-newer-than-file-p? -- cheers, Thorsten ^ permalink raw reply [flat|nested] 11+ messages in thread
[parent not found: <mailman.3833.1341163416.855.help-gnu-emacs@gnu.org>]
* Re: How to compare time of last file modification? [not found] ` <mailman.3833.1341163416.855.help-gnu-emacs@gnu.org> @ 2012-07-01 17:36 ` Pascal J. Bourguignon 2012-07-01 21:11 ` Lars Magne Ingebrigtsen 2012-07-01 19:48 ` Barry Margolin 1 sibling, 1 reply; 11+ messages in thread From: Pascal J. Bourguignon @ 2012-07-01 17:36 UTC (permalink / raw) To: help-gnu-emacs Thorsten Jolitz <tjolitz@googlemail.com> writes: > Is there a reason to prefer time-less-p or the custom-made solutions > over file-newer-than-file-p? file-newer-than-file-p use the OS provided m_time types to compare. time-less-p uses a 1-second resolution, 32-bit representation of time. Therefore? -- __Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: How to compare time of last file modification? 2012-07-01 17:36 ` Pascal J. Bourguignon @ 2012-07-01 21:11 ` Lars Magne Ingebrigtsen 0 siblings, 0 replies; 11+ messages in thread From: Lars Magne Ingebrigtsen @ 2012-07-01 21:11 UTC (permalink / raw) To: help-gnu-emacs "Pascal J. Bourguignon" <pjb@informatimago.com> writes: > file-newer-than-file-p use the OS provided m_time types to compare. > time-less-p uses a 1-second resolution, 32-bit representation of time. No, `time-less-p' (now) uses the resolution that the OS exposes to Emacs, which, on most OS-es, is a lot more fine-grained than 1 second. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog http://lars.ingebrigtsen.no/ ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: How to compare time of last file modification? [not found] ` <mailman.3833.1341163416.855.help-gnu-emacs@gnu.org> 2012-07-01 17:36 ` Pascal J. Bourguignon @ 2012-07-01 19:48 ` Barry Margolin 2012-07-01 20:26 ` Thorsten Jolitz 1 sibling, 1 reply; 11+ messages in thread From: Barry Margolin @ 2012-07-01 19:48 UTC (permalink / raw) To: help-gnu-emacs In article <mailman.3833.1341163416.855.help-gnu-emacs@gnu.org>, Thorsten Jolitz <tjolitz@googlemail.com> wrote: > Is there a reason to prefer time-less-p or the custom-made solutions > over file-newer-than-file-p? file-newer-than-file-p is only applicable when you're comparing two files. If you're comparing a file's modification time to some other time, then you need to use time-less-p. -- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me *** ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: How to compare time of last file modification? 2012-07-01 19:48 ` Barry Margolin @ 2012-07-01 20:26 ` Thorsten Jolitz 0 siblings, 0 replies; 11+ messages in thread From: Thorsten Jolitz @ 2012-07-01 20:26 UTC (permalink / raw) To: help-gnu-emacs Barry Margolin <barmar@alum.mit.edu> writes: > In article <mailman.3833.1341163416.855.help-gnu-emacs@gnu.org>, > Thorsten Jolitz <tjolitz@googlemail.com> wrote: > >> Is there a reason to prefer time-less-p or the custom-made solutions >> over file-newer-than-file-p? > > file-newer-than-file-p is only applicable when you're comparing two > files. If you're comparing a file's modification time to some other > time, then you need to use time-less-p. I see, thanks. -- cheers, Thorsten ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2012-07-01 21:11 UTC | newest] Thread overview: 11+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2012-07-01 0:38 How to compare time of last file modification? Thorsten Jolitz 2012-07-01 0:41 ` Thorsten Jolitz [not found] <mailman.3790.1341102956.855.help-gnu-emacs@gnu.org> 2012-07-01 1:16 ` Pascal J. Bourguignon 2012-07-01 8:56 ` Thorsten Jolitz 2012-07-01 9:23 ` Michael Albinus 2012-07-01 10:13 ` Lars Magne Ingebrigtsen 2012-07-01 17:26 ` Thorsten Jolitz [not found] ` <mailman.3833.1341163416.855.help-gnu-emacs@gnu.org> 2012-07-01 17:36 ` Pascal J. Bourguignon 2012-07-01 21:11 ` Lars Magne Ingebrigtsen 2012-07-01 19:48 ` Barry Margolin 2012-07-01 20:26 ` Thorsten Jolitz
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 read-only IMAP folder(s) and NNTP newsgroup(s).