all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: shawn boles <shawn.boles@gmail.com>
To: Andreas Schwab <schwab@linux-m68k.org>
Cc: 6957@debbugs.gnu.org
Subject: bug#6957: url-cookie-expired-p Redux (at last)
Date: Thu, 2 Sep 2010 10:13:39 -0700	[thread overview]
Message-ID: <AANLkTikxS8uHphJ7Utyz0YYsj9rLW4pEc=KQon23-CoE@mail.gmail.com> (raw)
In-Reply-To: <AANLkTiktdGTAynhkiUKOkBdMRMd40gsy2Mk3OdL8qU42@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1074 bytes --]

On Tue, Aug 31, 2010 at 4:39 PM, Andreas Schwab <schwab@linux-m68k.org> wrote:
> (float-time) already gives the seconds since epoch.  No need to convert
> to string and back, or doing any time zone adjustments.

I spent yesterday laid up with a cold. Between naps I found myself
coming back to (url-cookie-expired-p) and Andreas' response to my GMT
conversion. I kept thinking that there must be kernel of wisdom for
this grasshopper to find.

I would like to suggest the following replacement for
(url-cookie-expired-p); please see attached patch.

(defun url-cookie-expired-p (cookie)
	(let* ((exp (url-cookie-expires cookie))
				 (exp-time (and exp (float-time (date-to-time exp)))))
		(if (not exp) nil
			(> (float-time) exp-time))))

If the cookie has an expiration date, (float-time (date-to-time exp))
takes care of converting this to a float time, adjusted to the
client's time zone. Then all we need to do is compare this exp-time
against (float-time).

As an added bonus, we can now remove the url-cookie dependency on timezone.

shawn

[-- Attachment #2: url-cookie.el.patch --]
[-- Type: application/octet-stream, Size: 2240 bytes --]

--- /cygdrive/c/src/Emacs/emacs-23.2/emacs-23.2/lisp/url/url-cookie.el	2010-08-31 10:53:08.860091900 -0700
+++ url-cookie.el	2010-09-02 10:06:09.694111100 -0700
@@ -24,7 +24,6 @@
 
 ;;; Code:
 
-(require 'timezone)
 (require 'url-util)
 (require 'url-parse)
 (eval-when-compile (require 'cl))
@@ -194,34 +193,12 @@
 	(setq url-cookie-storage (list (list domain tmp))))))))
 
 (defun url-cookie-expired-p (cookie)
-  (let* (
-	 (exp (url-cookie-expires cookie))
-	 (cur-date (and exp (timezone-parse-date (current-time-string))))
-	 (exp-date (and exp (timezone-parse-date exp)))
-	 (cur-greg (and cur-date (timezone-absolute-from-gregorian
-				  (string-to-number (aref cur-date 1))
-				  (string-to-number (aref cur-date 2))
-				  (string-to-number (aref cur-date 0)))))
-	 (exp-greg (and exp (timezone-absolute-from-gregorian
-			     (string-to-number (aref exp-date 1))
-			     (string-to-number (aref exp-date 2))
-			     (string-to-number (aref exp-date 0)))))
-	 (diff-in-days (and exp (- cur-greg exp-greg)))
-	 )
-    (cond
-     ((not exp)	nil)			; No expiry == expires at browser quit
-     ((< diff-in-days 0) nil)		; Expires sometime after today
-     ((> diff-in-days 0) t)		; Expired before today
-     (t					; Expires sometime today, check times
-      (let* ((cur-time (timezone-parse-time (aref cur-date 3)))
-	     (exp-time (timezone-parse-time (aref exp-date 3)))
-	     (cur-norm (+ (* 360 (string-to-number (aref cur-time 2)))
-			  (*  60 (string-to-number (aref cur-time 1)))
-			  (*   1 (string-to-number (aref cur-time 0)))))
-	     (exp-norm (+ (* 360 (string-to-number (aref exp-time 2)))
-			  (*  60 (string-to-number (aref exp-time 1)))
-			  (*   1 (string-to-number (aref exp-time 0))))))
-	(> (- cur-norm exp-norm) 1))))))
+	"Returns true if COOKIE is expired.
+If COOKIE has an expiration date it is converted to seconds, adjusted to the client timezone and then compared against (float-time)." 
+	(let* ((exp (url-cookie-expires cookie))
+				 (exp-time (and exp (float-time (date-to-time exp)))))
+		(if (not exp) nil	(> (float-time) exp-time)))
+	)
 
 (defun url-cookie-retrieve (host &optional localpart secure)
   "Retrieve all the netscape-style cookies for a specified HOST and LOCALPART."

  parent reply	other threads:[~2010-09-02 17:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-31 20:07 bug#6957: url-cookie-expired-p shawn boles
2010-08-31 22:51 ` bug#6957: url-cookie-expired-p Redux shawn boles
2010-08-31 23:39   ` Andreas Schwab
2010-09-01  0:43     ` shawn boles
2010-09-02 17:13 ` shawn boles [this message]
2010-09-09  5:39   ` bug#6957: url-cookie-expired-p Redux (at last) Glenn Morris

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='AANLkTikxS8uHphJ7Utyz0YYsj9rLW4pEc=KQon23-CoE@mail.gmail.com' \
    --to=shawn.boles@gmail.com \
    --cc=6957@debbugs.gnu.org \
    --cc=schwab@linux-m68k.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.