Commit b0ede6b3 authored by David Byers's avatar David Byers
Browse files

Support (and use) UTC time format in the protocol.

Detailed changes:
> 	Support UTC time in the server:
> 	* startup.el (lyskom): Select UTC time format if the server
> 	supports it.
>
> 	* utilities.el (lyskom-set-connection-format): New function.
>
> 	* parse.el (lyskom-parse-time): Use lyskom-create-time-from-utc.
> 	Convert day-of-year to starting from one.
> 	(lyskom-init-parse): Add the parse buffer as a child of the main
> 	buffer so UTC setting is propagated to it.
>
> 	* komtypes.el (lyskom-create-time-from-utc): Simplified. It seems
> 	that the right thing to do is pass zero in TZ to encode-time. This
> 	should speed things up slightly in normal cases. Handle case when
> 	server does not use UTC.
>
> 	* services.el: (initiate-get-last-text): Commented out since we
> 	can't convert local time to UTC, which this function requires.
>
parent 8cf072e5
2003-08-17 David Byers <byers@lysator.liu.se>
Support UTC time in the server:
* startup.el (lyskom): Select UTC time format if the server
supports it.
* utilities.el (lyskom-set-connection-format): New function.
* parse.el (lyskom-parse-time): Use lyskom-create-time-from-utc.
Convert day-of-year to starting from one.
(lyskom-init-parse): Add the parse buffer as a child of the main
buffer so UTC setting is propagated to it.
* komtypes.el (lyskom-create-time-from-utc): Simplified. It seems
that the right thing to do is pass zero in TZ to encode-time. This
should speed things up slightly in normal cases. Handle case when
server does not use UTC.
* services.el: (initiate-get-last-text): Commented out since we
can't convert local time to UTC, which this function requires.
Go over EMPTY and MUSTMATCH parameters to lyskom-read-conf-stat:
* startup.el (kom-start-anew): Don't allow EMPTY when logging on.
......
......@@ -140,7 +140,7 @@ a child of some buffer, reparent it."
(setq done (cons current done))
(setq queue (append queue (lyskom-get-buffer-children current)))
(funcall function current)))))
(defun lyskom-map-buffer-children (function buffer)
"Apply FUNCTION to each child of BUFFER and make a list of the results."
......
......@@ -395,30 +395,29 @@ Automatically created with def-komtype" type)
:nil-safe)
(defun lyskom-create-time-from-utc (sec min hour mday mon year
wday yday isdst tzhr tzmin)
(let* ((tz (current-time-zone))
(date (decode-time
(encode-time sec min hour mday mon year (elt tz 1)))))
;; Date is (SEC MINUTE HOUR DAY MONTH YEAR DOW DST ZONE)
;; 0 1 2 3 4 5 6 7 8
(unless (eq mday (elt date 3))
(setq yday (if (< (car tz) 0) (- yday 1) (+ yday 1)))
(cond ((< yday 1) (setq yday (lyskom-days-in-year (elt date 5))))
((> yday (lyskom-days-in-year year)) (setq yday 1))))
(lyskom-create-time (elt date 0) ; sec
(elt date 1) ; min
(elt date 2) ; hour
(elt date 3) ; mday
(elt date 4) ; mon
(elt date 5) ; year
(elt date 6) ; dow
yday ; yday
(elt date 7) ; dst
nil nil)
))
wday yday isdst &optional tzhr tzmin)
(if lyskom-server-uses-utc
(let* ((date (decode-time (encode-time sec min hour mday mon year 0))))
(unless (eq mday (elt date 3))
(setq yday (if (< (or (car (current-time-zone)) 0) 0)
(- yday 1) (+ yday 1)))
(cond ((< yday 1) (setq yday (lyskom-days-in-year (elt date 5))))
((> yday (lyskom-days-in-year year)) (setq yday 1))))
(lyskom-create-time (elt date 0) ; sec
(elt date 1) ; min
(elt date 2) ; hour
(elt date 3) ; mday
(elt date 4) ; mon
(elt date 5) ; year
(elt date 6) ; dow
yday ; yday
(elt date 7) ; dst
nil nil)
)
(lyskom-create-time sec min hour mday mon year
wday yday isdst tzhr tzmin)))
;;; ================================================================
;;; privs
......
......@@ -3909,8 +3909,7 @@ If MEMBERSHIPs prioriy is 0, it always returns nil."
(delete-region (point-min) (- (point-max) lyskom-debug-communications-limit))))
(defun lyskom-debug-insert (proc prefix string)
(let* ((buf (get-buffer-create
lyskom-debug-communications-to-buffer-buffer))
(let* ((buf (get-buffer-create lyskom-debug-communications-to-buffer-buffer))
(win (get-buffer-window buf 'visible)))
(if win
(save-excursion
......
......@@ -312,7 +312,7 @@ Signal lyskom-parse-incomplete if there is no nonwhite char to parse."
(defun lyskom-parse-time ()
"Parse a time from server. Args: none."
(lyskom-create-time
(lyskom-create-time-from-utc
(lyskom-parse-num) ;sec
(lyskom-parse-num) ;min
(lyskom-parse-num) ;hour
......@@ -320,7 +320,7 @@ Signal lyskom-parse-incomplete if there is no nonwhite char to parse."
(1+ (lyskom-parse-num)) ;mon
(+ 1900 (lyskom-parse-num)) ;year
(lyskom-parse-num) ;wday
(lyskom-parse-num) ;yday
(1+ (lyskom-parse-num)) ;yday
(lyskom-parse-num))) ;isdst
......@@ -1164,6 +1164,7 @@ i.e creates the buffer, sets all markers and pointers."
(concat (if lyskom-debug-communications-to-buffer "" " ")
(buffer-name)
"-replies")))
(lyskom-set-buffer-parent lyskom-unparsed-buffer lyskom-buffer)
(save-excursion (set-buffer lyskom-unparsed-buffer)
(lyskom-set-buffer-multibyte nil))
(setq lyskom-unparsed-marker
......
......@@ -850,12 +850,17 @@ Args: KOM-QUEUE HANDLER PERS-NO TEXT-NO &rest DATA."
(lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-void)
(lyskom-send-packet kom-queue (lyskom-format-objects 57 pers-no text-no))))
(defun initiate-get-last-text (kom-queue handler before &rest data)
"Get text created before BEFORE.
Args: KOM-QUEUE HANDLER BEFORE &rest DATA"
(lyskom-server-call
(lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-num)
(lyskom-send-packet kom-queue (lyskom-format-objects 58 before))))
;; WARNING: If you start using this you have to figure out a way to
;; convert local time (before) to UTC. Since this doesn't work at the
;; moment, I have commented this functoun into oblivion.
;;
;; (defun initiate-get-last-text (kom-queue handler before &rest data)
;; "Get text created before BEFORE.
;; Args: KOM-QUEUE HANDLER BEFORE &rest DATA"
;; (lyskom-server-call
;; (lyskom-call kom-queue lyskom-ref-no handler data 'lyskom-parse-num)
;; (lyskom-send-packet kom-queue (lyskom-format-objects 58 before))))
(defun initiate-create-anonymous-text (kom-queue
......
......@@ -261,6 +261,9 @@ clients of the event. See lyskom-mode for details on lyskom."
(save-excursion
(lyskom-init-parse buffer))
;; Set up timestamps and stuff
(lyskom-set-connection-time-format t)
;; Async messages
(lyskom-accept-async)
......
......@@ -2157,4 +2157,16 @@ suitable for use as initial input in a magic minibuffer."
(lyskom-with-magic-minibuffer
(or (read-from-minibuffer prompt initial-contents keymap read hist) def))))
(defun lyskom-set-connection-time-format (val)
"Change protocol time format to UTC if VAL is non-nil."
(when (or (blocking-do 'set-connection-time-format val)
(null val))
(lyskom-traverse-buffer-hierarchy
(lambda (buf)
(save-excursion
(set-buffer buf)
(make-variable-buffer-local 'lyskom-server-uses-utc)
(setq lyskom-server-uses-utc val)))
lyskom-buffer)))
(put 'lyskom-with-magic-minibuffer 'edebug-form-spec '(body))
......@@ -3207,6 +3207,11 @@ Users are encouraged to use their best sense of humor."
(defvar lyskom-max-int 8388607
"The largest int Emacs, and thus this LysKOM client, can handle.")
(def-kom-var lyskom-server-uses-utc nil
"When non-nil, assume that the server uses UTC timestamps."
inherited
local)
(defconst lyskom-server-features
'((10 lyskom-bcc-flag
lyskom-extended-types-flag)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment