Function: sunrise-sunset

sunrise-sunset is an autoloaded, interactive and byte-compiled function defined in solar.el.gz.

Signature

(sunrise-sunset &optional ARG)

Documentation

Local time of sunrise and sunset for today. Accurate to a few seconds.

If called with an optional prefix argument ARG, prompt for date. If called with an optional double prefix argument, prompt for longitude, latitude, time zone, and date, and always use standard time.

This function is suitable for execution in an init file.

View in manual

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/solar.el.gz
;; FIXME but there already is solar-sunrise-sunset.
;;;###autoload
(defun sunrise-sunset (&optional arg)
  "Local time of sunrise and sunset for today.  Accurate to a few seconds.
If called with an optional prefix argument ARG, prompt for date.
If called with an optional double prefix argument, prompt for
longitude, latitude, time zone, and date, and always use standard time.

This function is suitable for execution in an init file."
  (interactive "p")
  (or arg (setq arg 1))
  (if (and (< arg 16)
           (not (and calendar-latitude calendar-longitude calendar-time-zone)))
      (solar-setup))
  (let* ((calendar-longitude
          (if (< arg 16) calendar-longitude
            (solar-get-number
             "Enter longitude (decimal fraction; + east, - west): ")))
         (calendar-latitude
          (if (< arg 16) calendar-latitude
            (solar-get-number
             "Enter latitude (decimal fraction; + north, - south): ")))
         (calendar-time-zone
          (if (< arg 16) calendar-time-zone
            (solar-get-number
             "Enter difference from Coordinated Universal Time (in minutes): ")))
         (calendar-location-name
          (if (< arg 16) calendar-location-name
            (let ((float-output-format "%.1f"))
              (format "%s%s, %s%s"
                      (if (numberp calendar-latitude)
                          (abs calendar-latitude)
                        (+ (aref calendar-latitude 0)
                           (/ (aref calendar-latitude 1) 60.0)))
                      (if (numberp calendar-latitude)
                          (if (> calendar-latitude 0) "N" "S")
                        (if (eq (aref calendar-latitude 2) 'north) "N" "S"))
                      (if (numberp calendar-longitude)
                          (abs calendar-longitude)
                        (+ (aref calendar-longitude 0)
                           (/ (aref calendar-longitude 1) 60.0)))
                      (if (numberp calendar-longitude)
                          (if (> calendar-longitude 0) "E" "W")
                        (if (eq (aref calendar-longitude 2) 'east)
                            "E" "W"))))))
         (calendar-standard-time-zone-name
          (if (< arg 16) calendar-standard-time-zone-name
            (cond ((zerop calendar-time-zone)
                   (if (eq calendar-time-zone-style 'numeric)
                       "+0000" "UTC"))
                  ((< calendar-time-zone 0)
                   (format "UTC%dmin" calendar-time-zone))
                  (t  (format "UTC+%dmin" calendar-time-zone)))))
         (calendar-daylight-savings-starts
          (if (< arg 16) calendar-daylight-savings-starts))
         (calendar-daylight-savings-ends
          (if (< arg 16) calendar-daylight-savings-ends))
         (date (if (< arg 4) (calendar-current-date) (calendar-read-date)))
         (date-string (calendar-date-string date t))
         (time-string (solar-sunrise-sunset-string date))
         (msg (format "%s%s"
                      (if (< arg 4) ""  ; don't print date if it's today's
                        (format "%s: " date-string))
                      time-string)))
    (message "%s" msg)
    msg))