diff options
| author | Jay Belanger | 2007-08-25 01:37:13 +0000 |
|---|---|---|
| committer | Jay Belanger | 2007-08-25 01:37:13 +0000 |
| commit | 94a954954c7b2f3d63e455c1c2a9ee219e4ec7ae (patch) | |
| tree | b561547d9e26c243f46046a4119da57a38cdc0eb | |
| parent | 3707a0017b003c105bb0d8f54d0233887822cc39 (diff) | |
| download | emacs-94a954954c7b2f3d63e455c1c2a9ee219e4ec7ae.tar.gz emacs-94a954954c7b2f3d63e455c1c2a9ee219e4ec7ae.zip | |
(var-TimeZone): Make nil the default value.
(math-calendar-tzinfo): New variable.
(math-get-calendar-tzinfo): New function.
(calcFunc-tzone, calcFunc-dst): Use Emacs's calendar
to get information when zone is nil.
| -rw-r--r-- | lisp/ChangeLog | 9 | ||||
| -rw-r--r-- | lisp/calc/calc-forms.el | 135 |
2 files changed, 85 insertions, 59 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index ccf7d130c52..bce24e6d625 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,12 @@ | |||
| 1 | 2007-08-25 Jay Belanger <jay.p.belanger@gmail.com> | ||
| 2 | |||
| 3 | * calc/calc-forms.el (var-TimeZone): Make nil explicitly | ||
| 4 | the default value. | ||
| 5 | (math-calendar-tzinfo): New variable. | ||
| 6 | (math-get-calendar-tzinfo): New function. | ||
| 7 | (calcFunc-tzone, calcFunc-dst): Use Emacs's calendar | ||
| 8 | to get information when zone is nil. | ||
| 9 | |||
| 1 | 2007-08-24 Dan Nicolaescu <dann@ics.uci.edu> | 10 | 2007-08-24 Dan Nicolaescu <dann@ics.uci.edu> |
| 2 | 11 | ||
| 3 | * log-view.el (log-view-toggle-mark-entry): New function. | 12 | * log-view.el (log-view-toggle-mark-entry): New function. |
diff --git a/lisp/calc/calc-forms.el b/lisp/calc/calc-forms.el index 7ac0a0bb0db..3839fc93666 100644 --- a/lisp/calc/calc-forms.el +++ b/lisp/calc/calc-forms.el | |||
| @@ -1201,7 +1201,29 @@ as measured in the integer number of days before January 1 of the year 1AD.") | |||
| 1201 | ) | 1201 | ) |
| 1202 | "No doc yet. See calc manual for now. ") | 1202 | "No doc yet. See calc manual for now. ") |
| 1203 | 1203 | ||
| 1204 | (defvar var-TimeZone) | 1204 | (defvar var-TimeZone nil) |
| 1205 | |||
| 1206 | ;; From cal-dst | ||
| 1207 | (defvar calendar-current-time-zone-cache) | ||
| 1208 | |||
| 1209 | (defvar math-calendar-tzinfo | ||
| 1210 | nil | ||
| 1211 | "Information about the timezone, retrieved from the calendar.") | ||
| 1212 | |||
| 1213 | (defun math-get-calendar-tzinfo () | ||
| 1214 | "Get information about the timezone from the calendar. | ||
| 1215 | The result should be a list of two items about the current time zone: | ||
| 1216 | first, the number of seconds difference from GMT | ||
| 1217 | second, the number of seconds offset for daylight savings." | ||
| 1218 | (if math-calendar-tzinfo | ||
| 1219 | math-calendar-tzinfo | ||
| 1220 | (require 'cal-dst) | ||
| 1221 | (let ((tzinfo (progn | ||
| 1222 | (calendar-current-time-zone) | ||
| 1223 | calendar-current-time-zone-cache))) | ||
| 1224 | (setq math-calendar-tzinfo | ||
| 1225 | (list (* 60 (abs (nth 0 tzinfo))) | ||
| 1226 | (* 60 (nth 1 tzinfo))))))) | ||
| 1205 | 1227 | ||
| 1206 | (defun calcFunc-tzone (&optional zone date) | 1228 | (defun calcFunc-tzone (&optional zone date) |
| 1207 | (if zone | 1229 | (if zone |
| @@ -1233,53 +1255,9 @@ as measured in the integer number of days before January 1 of the year 1AD.") | |||
| 1233 | (t (math-reject-arg zone "*Expected a time zone"))) | 1255 | (t (math-reject-arg zone "*Expected a time zone"))) |
| 1234 | (if (calc-var-value 'var-TimeZone) | 1256 | (if (calc-var-value 'var-TimeZone) |
| 1235 | (calcFunc-tzone (calc-var-value 'var-TimeZone) date) | 1257 | (calcFunc-tzone (calc-var-value 'var-TimeZone) date) |
| 1236 | (let ((p math-tzone-names) | 1258 | (let ((tzinfo (math-get-calendar-tzinfo))) |
| 1237 | (offset 0) | 1259 | (+ (nth 0 tzinfo) |
| 1238 | (tz '(var error var-error))) | 1260 | (* (math-cal-daylight-savings-adjust date) (nth 1 tzinfo))))))) |
| 1239 | (save-excursion | ||
| 1240 | (set-buffer (get-buffer-create " *Calc Temporary*")) | ||
| 1241 | (erase-buffer) | ||
| 1242 | (call-process "date" nil t) | ||
| 1243 | (goto-char 1) | ||
| 1244 | (let ((case-fold-search t)) | ||
| 1245 | (while (and p (not (search-forward (car (car p)) nil t))) | ||
| 1246 | (setq p (cdr p)))) | ||
| 1247 | (if (looking-at "\\([-+][0-9]?[0-9]\\)\\([0-9][0-9]\\)?\\(\\'\\|[^0-9]\\)") | ||
| 1248 | (setq offset (math-add | ||
| 1249 | (string-to-number (buffer-substring | ||
| 1250 | (match-beginning 1) | ||
| 1251 | (match-end 1))) | ||
| 1252 | (if (match-beginning 2) | ||
| 1253 | (math-div (string-to-number (buffer-substring | ||
| 1254 | (match-beginning 2) | ||
| 1255 | (match-end 2))) | ||
| 1256 | 60) | ||
| 1257 | 0))))) | ||
| 1258 | (if p | ||
| 1259 | (progn | ||
| 1260 | (setq p (car p)) | ||
| 1261 | ;; Try to convert to a generalized time zone. | ||
| 1262 | (if (integerp (nth 2 p)) | ||
| 1263 | (let ((gen math-tzone-names)) | ||
| 1264 | (while (and gen | ||
| 1265 | (not (equal (nth 2 (car gen)) (car p))) | ||
| 1266 | (not (equal (nth 3 (car gen)) (car p))) | ||
| 1267 | (not (equal (nth 4 (car gen)) (car p))) | ||
| 1268 | (not (equal (nth 5 (car gen)) (car p)))) | ||
| 1269 | (setq gen (cdr gen))) | ||
| 1270 | (and gen | ||
| 1271 | (setq gen (car gen)) | ||
| 1272 | (equal (math-daylight-savings-adjust nil (car gen)) | ||
| 1273 | (nth 2 p)) | ||
| 1274 | (setq p gen)))) | ||
| 1275 | (setq tz (math-add (list 'var | ||
| 1276 | (intern (car p)) | ||
| 1277 | (intern (concat "var-" (car p)))) | ||
| 1278 | offset)))) | ||
| 1279 | (kill-buffer " *Calc Temporary*") | ||
| 1280 | (setq var-TimeZone tz) | ||
| 1281 | (calc-refresh-evaltos 'var-TimeZone) | ||
| 1282 | (calcFunc-tzone tz date))))) | ||
| 1283 | 1261 | ||
| 1284 | (defvar math-daylight-savings-hook 'math-std-daylight-savings) | 1262 | (defvar math-daylight-savings-hook 'math-std-daylight-savings) |
| 1285 | 1263 | ||
| @@ -1300,21 +1278,60 @@ as measured in the integer number of days before January 1 of the year 1AD.") | |||
| 1300 | (and math-daylight-savings-hook | 1278 | (and math-daylight-savings-hook |
| 1301 | (funcall math-daylight-savings-hook date dt zone bump)))) | 1279 | (funcall math-daylight-savings-hook date dt zone bump)))) |
| 1302 | 1280 | ||
| 1281 | ;;; Based on part of dst-adjust-time in cal-dst.el | ||
| 1282 | ;;; For calcFunc-dst, when zone=nil | ||
| 1283 | (defun math-cal-daylight-savings-adjust (date) | ||
| 1284 | "Return -1 if DATE is using daylight saving, 0 otherwise." | ||
| 1285 | (require 'cal-dst) | ||
| 1286 | (unless date (setq date (calcFunc-now))) | ||
| 1287 | (let* ((dt (math-date-to-dt date)) | ||
| 1288 | (time (cond | ||
| 1289 | ((nth 3 dt) | ||
| 1290 | (nth 3 dt)) | ||
| 1291 | ((nth 4 dt) | ||
| 1292 | (+ (nth 3 dt) (/ (nth 4 dt) 60.0))) | ||
| 1293 | (t | ||
| 1294 | 0))) | ||
| 1295 | (rounded-abs-date | ||
| 1296 | (+ | ||
| 1297 | (calendar-absolute-from-gregorian | ||
| 1298 | (list (nth 1 dt) (nth 2 dt) (nth 0 dt))) | ||
| 1299 | (/ (round (* 60 time)) 60.0 24.0)))) | ||
| 1300 | (if (dst-in-effect rounded-abs-date) | ||
| 1301 | -1 | ||
| 1302 | 0))) | ||
| 1303 | |||
| 1303 | (defun calcFunc-dsadj (date &optional zone) | 1304 | (defun calcFunc-dsadj (date &optional zone) |
| 1304 | (if zone | 1305 | (if zone |
| 1305 | (or (eq (car-safe zone) 'var) | 1306 | (or (eq (car-safe zone) 'var) |
| 1306 | (math-reject-arg zone "*Time zone variable expected")) | 1307 | (math-reject-arg zone "*Time zone variable expected")) |
| 1307 | (setq zone (or (calc-var-value 'var-TimeZone) | 1308 | (setq zone (calc-var-value 'var-TimeZone))) |
| 1308 | (progn | 1309 | (if zone |
| 1309 | (calcFunc-tzone) | 1310 | (progn |
| 1310 | (calc-var-value 'var-TimeZone))))) | 1311 | (setq zone (and (eq (car-safe zone) 'var) |
| 1311 | (setq zone (and (eq (car-safe zone) 'var) | 1312 | (upcase (symbol-name (nth 1 zone))))) |
| 1312 | (upcase (symbol-name (nth 1 zone))))) | 1313 | (let ((zadj (assoc zone math-tzone-names))) |
| 1313 | (let ((zadj (assoc zone math-tzone-names))) | 1314 | (or zadj (math-reject-arg zone "*Unrecognized time zone name")) |
| 1314 | (or zadj (math-reject-arg zone "*Unrecognized time zone name")) | 1315 | (if (integerp (nth 2 zadj)) |
| 1315 | (if (integerp (nth 2 zadj)) | 1316 | (nth 2 zadj) |
| 1316 | (nth 2 zadj) | 1317 | (math-daylight-savings-adjust date zone)))) |
| 1317 | (math-daylight-savings-adjust date zone)))) | 1318 | (math-cal-daylight-savings-adjust date))) |
| 1319 | |||
| 1320 | ;; (defun calcFunc-dsadj (date &optional zone) | ||
| 1321 | ;; (if zone | ||
| 1322 | ;; (or (eq (car-safe zone) 'var) | ||
| 1323 | ;; (math-reject-arg zone "*Time zone variable expected")) | ||
| 1324 | ;; (setq zone (or (calc-var-value 'var-TimeZone) | ||
| 1325 | ;; (progn | ||
| 1326 | ;; (calcFunc-tzone) | ||
| 1327 | ;; (calc-var-value 'var-TimeZone))))) | ||
| 1328 | ;; (setq zone (and (eq (car-safe zone) 'var) | ||
| 1329 | ;; (upcase (symbol-name (nth 1 zone))))) | ||
| 1330 | ;; (let ((zadj (assoc zone math-tzone-names))) | ||
| 1331 | ;; (or zadj (math-reject-arg zone "*Unrecognized time zone name")) | ||
| 1332 | ;; (if (integerp (nth 2 zadj)) | ||
| 1333 | ;; (nth 2 zadj) | ||
| 1334 | ;; (math-daylight-savings-adjust date zone)))) | ||
| 1318 | 1335 | ||
| 1319 | (defun calcFunc-tzconv (date z1 z2) | 1336 | (defun calcFunc-tzconv (date z1 z2) |
| 1320 | (if (math-realp date) | 1337 | (if (math-realp date) |