comparison lisp/calc/calc-forms.el @ 62035:0e0c15279b4e

(calc-time, calc-date-notation, math-this-year, math-parse-date) (math-parse-standard-date, calcFunc-tzone): Replace string-to-int by string-to-number.
author Jay Belanger <jay.p.belanger@gmail.com>
date Mon, 02 May 2005 19:42:52 +0000
parents 7b8e42efa46a
children 842c8b2c2940 08185296b491
comparison
equal deleted inserted replaced
62034:b00f3dbbb0b5 62035:0e0c15279b4e
37 (calc-wrapper 37 (calc-wrapper
38 (let ((time (current-time-string))) 38 (let ((time (current-time-string)))
39 (calc-enter-result 0 "time" 39 (calc-enter-result 0 "time"
40 (list 'mod 40 (list 'mod
41 (list 'hms 41 (list 'hms
42 (string-to-int (substring time 11 13)) 42 (string-to-number (substring time 11 13))
43 (string-to-int (substring time 14 16)) 43 (string-to-number (substring time 14 16))
44 (string-to-int (substring time 17 19))) 44 (string-to-number (substring time 17 19)))
45 (list 'hms 24 0 0)))))) 45 (list 'hms 24 0 0))))))
46 46
47 (defun calc-to-hms (arg) 47 (defun calc-to-hms (arg)
48 (interactive "P") 48 (interactive "P")
49 (calc-wrapper 49 (calc-wrapper
78 (interactive "sDate format (e.g., M/D/YY h:mm:ss): \nP") 78 (interactive "sDate format (e.g., M/D/YY h:mm:ss): \nP")
79 (calc-wrapper 79 (calc-wrapper
80 (if (equal fmt "") 80 (if (equal fmt "")
81 (setq fmt "1")) 81 (setq fmt "1"))
82 (if (string-match "\\` *[0-9] *\\'" fmt) 82 (if (string-match "\\` *[0-9] *\\'" fmt)
83 (setq fmt (nth (string-to-int fmt) calc-standard-date-formats))) 83 (setq fmt (nth (string-to-number fmt) calc-standard-date-formats)))
84 (or (string-match "[a-zA-Z]" fmt) 84 (or (string-match "[a-zA-Z]" fmt)
85 (error "Bad date format specifier")) 85 (error "Bad date format specifier"))
86 (and arg 86 (and arg
87 (>= (setq arg (prefix-numeric-value arg)) 0) 87 (>= (setq arg (prefix-numeric-value arg)) 0)
88 (<= arg 9) 88 (<= arg 9)
439 ftime 439 ftime
440 (math-sub time ftime)))) 440 (math-sub time ftime))))
441 441
442 442
443 (defun math-this-year () 443 (defun math-this-year ()
444 (string-to-int (substring (current-time-string) -4))) 444 (string-to-number (substring (current-time-string) -4)))
445 445
446 (defun math-leap-year-p (year) 446 (defun math-leap-year-p (year)
447 (if (Math-lessp year 1752) 447 (if (Math-lessp year 1752)
448 (if (math-negp year) 448 (if (math-negp year)
449 (= (math-imod (math-neg year) 4) 1) 449 (= (math-imod (math-neg year) 4) 1)
728 728
729 ;; Extract the time, if any. 729 ;; Extract the time, if any.
730 (if (or (string-match "\\([0-9][0-9]?\\):\\([0-9][0-9]?\\)\\(:\\([0-9][0-9]?\\(\\.[0-9]+\\)?\\)\\)? *\\([ap]m?\\|[ap]\\. *m\\.\\|noon\\|n\\>\\|midnight\\|mid\\>\\|m\\>\\)?" math-pd-str) 730 (if (or (string-match "\\([0-9][0-9]?\\):\\([0-9][0-9]?\\)\\(:\\([0-9][0-9]?\\(\\.[0-9]+\\)?\\)\\)? *\\([ap]m?\\|[ap]\\. *m\\.\\|noon\\|n\\>\\|midnight\\|mid\\>\\|m\\>\\)?" math-pd-str)
731 (string-match "\\([0-9][0-9]?\\)\\(\\)\\(\\(\\(\\)\\)\\) *\\([ap]m?\\|[ap]\\. *m\\.\\|noon\\|n\\>\\|midnight\\|mid\\>\\|m\\>\\)" math-pd-str)) 731 (string-match "\\([0-9][0-9]?\\)\\(\\)\\(\\(\\(\\)\\)\\) *\\([ap]m?\\|[ap]\\. *m\\.\\|noon\\|n\\>\\|midnight\\|mid\\>\\|m\\>\\)" math-pd-str))
732 (let ((ampm (math-match-substring math-pd-str 6))) 732 (let ((ampm (math-match-substring math-pd-str 6)))
733 (setq hour (string-to-int (math-match-substring math-pd-str 1)) 733 (setq hour (string-to-number (math-match-substring math-pd-str 1))
734 minute (math-match-substring math-pd-str 2) 734 minute (math-match-substring math-pd-str 2)
735 second (math-match-substring math-pd-str 4) 735 second (math-match-substring math-pd-str 4)
736 math-pd-str (concat (substring math-pd-str 0 (match-beginning 0)) 736 math-pd-str (concat (substring math-pd-str 0 (match-beginning 0))
737 (substring math-pd-str (match-end 0)))) 737 (substring math-pd-str (match-end 0))))
738 (if (equal minute "") 738 (if (equal minute "")
739 (setq minute 0) 739 (setq minute 0)
740 (setq minute (string-to-int minute))) 740 (setq minute (string-to-number minute)))
741 (if (equal second "") 741 (if (equal second "")
742 (setq second 0) 742 (setq second 0)
743 (setq second (math-read-number second))) 743 (setq second (math-read-number second)))
744 (if (equal ampm "") 744 (if (equal ampm "")
745 (if (> hour 23) 745 (if (> hour 23)
799 799
800 ;; Collect remaining numbers. 800 ;; Collect remaining numbers.
801 (setq temp 0) 801 (setq temp 0)
802 (while (string-match "[0-9]+" math-pd-str temp) 802 (while (string-match "[0-9]+" math-pd-str temp)
803 (and c (throw 'syntax "Too many numbers in date")) 803 (and c (throw 'syntax "Too many numbers in date"))
804 (setq c (string-to-int (math-match-substring math-pd-str 0))) 804 (setq c (string-to-number (math-match-substring math-pd-str 0)))
805 (or b (setq b c c nil)) 805 (or b (setq b c c nil))
806 (or a (setq a b b nil)) 806 (or a (setq a b b nil))
807 (setq temp (match-end 0))) 807 (setq temp (match-end 0)))
808 808
809 ;; Check that we have the right amount of information. 809 ;; Check that we have the right amount of information.
1019 hh HH mm ss SS))) 1019 hh HH mm ss SS)))
1020 (if (eq this 'ddd) 1020 (if (eq this 'ddd)
1021 (string-match "\\` *[0-9][0-9][0-9]" math-pd-str) 1021 (string-match "\\` *[0-9][0-9][0-9]" math-pd-str)
1022 (string-match "\\` *[0-9][0-9]" math-pd-str)) 1022 (string-match "\\` *[0-9][0-9]" math-pd-str))
1023 (string-match "\\` *[0-9]+" math-pd-str))) 1023 (string-match "\\` *[0-9]+" math-pd-str)))
1024 (and (setq num (string-to-int 1024 (and (setq num (string-to-number
1025 (math-match-substring math-pd-str 0)) 1025 (math-match-substring math-pd-str 0))
1026 math-pd-str (substring math-pd-str (match-end 0))) 1026 math-pd-str (substring math-pd-str (match-end 0)))
1027 nil)) 1027 nil))
1028 nil) 1028 nil)
1029 ((eq this 'W) 1029 ((eq this 'W)
1234 (let ((case-fold-search t)) 1234 (let ((case-fold-search t))
1235 (while (and p (not (search-forward (car (car p)) nil t))) 1235 (while (and p (not (search-forward (car (car p)) nil t)))
1236 (setq p (cdr p)))) 1236 (setq p (cdr p))))
1237 (if (looking-at "\\([-+][0-9]?[0-9]\\)\\([0-9][0-9]\\)?\\(\\'\\|[^0-9]\\)") 1237 (if (looking-at "\\([-+][0-9]?[0-9]\\)\\([0-9][0-9]\\)?\\(\\'\\|[^0-9]\\)")
1238 (setq offset (math-add 1238 (setq offset (math-add
1239 (string-to-int (buffer-substring 1239 (string-to-number (buffer-substring
1240 (match-beginning 1) 1240 (match-beginning 1)
1241 (match-end 1))) 1241 (match-end 1)))
1242 (if (match-beginning 2) 1242 (if (match-beginning 2)
1243 (math-div (string-to-int (buffer-substring 1243 (math-div (string-to-number (buffer-substring
1244 (match-beginning 2) 1244 (match-beginning 2)
1245 (match-end 2))) 1245 (match-end 2)))
1246 60) 1246 60)
1247 0))))) 1247 0)))))
1248 (if p 1248 (if p
1249 (progn 1249 (progn
1250 (setq p (car p)) 1250 (setq p (car p))