From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Pascal J. Bourguignon" Newsgroups: gmane.emacs.help Subject: Re: How to compare time of last file modification? Date: Sun, 01 Jul 2012 03:16:11 +0200 Organization: Informatimago Message-ID: <87bok0nuw4.fsf@kuiper.lan.informatimago.com> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1341105617 14143 80.91.229.3 (1 Jul 2012 01:20:17 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 1 Jul 2012 01:20:17 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Jul 01 03:20:15 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Sl8pi-0003dm-Kv for geh-help-gnu-emacs@m.gmane.org; Sun, 01 Jul 2012 03:20:14 +0200 Original-Received: from localhost ([::1]:55498 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sl8ph-0002O0-I6 for geh-help-gnu-emacs@m.gmane.org; Sat, 30 Jun 2012 21:20:13 -0400 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 117 Original-X-Trace: individual.net UH0OD8BC3lGFgcwvJfC2dwU82AtFodOgjOyNBQbYY2xwSRWxPSbR0KRwGvhsPwAvCq Cancel-Lock: sha1:NWUwNjdkNTliMDNkZTI2YTcxNTRiNDBhMjg0MzY3ZDNhZTUxODgwZQ== sha1:6vtVak5BnNjfNsX7N21ezUEfjkk= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) Original-Xref: usenet.stanford.edu gnu.emacs.help:193205 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:85596 Archived-At: Thorsten Jolitz 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 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 {}.