ISO emacs/elisp to determines dates corresponding to first/last days of a week, e.g. ISO 8601 2013-WW47

StackOverflow https://stackoverflow.com/questions/20055504

Вопрос

I like creating headings that look like

** WW47 (Monday November 18 - Sunday November 24, 2013)

I know how to use format-time-string, etc., in emacs/elisp to determine various definitions of the week-number (%U, %V, %W).

Q: how can I go backwards? In emacs/elisp, determine the dates of the first and last days of the week, given a year and week number?

More generally, parse a time-string such as ISO 8601 week-dates 2006-W52-7, or the week without day within week 2013-W46.

More generally still - many date and time representations imply date intervals. Weeks and months in particular imply intervals, although I suppose almost any time representation of a given precision can be interpreted as corresponding to an interval of time units less than the precision.

Q: are there (reasonably standard) emacs/elisp functions for determining first and last dates of a month, e.g. in terms of year/day-of-year format? Etc.

--

This post is mainly a "how do I do this in emacs/elisp?" question.

This sort of question appears to be quire common - there are similar questions on stackoverflow asking "how do I do this in Javascript/C#/..." etc., etc., etc.

I can do the math myself. But (a) better if there is a standard emacs/elisp function to do this, and (b) it is apparent from googling that there are many gotchas and issues, further emphasizing the goodness of using a standard library function, if one exists.

E.g. Getting first date in week given a year and weeknumber

Это было полезно?

Решение

I had a similar problem (see https://emacs.stackexchange.com/questions/43984/convert-between-iso-week-and-a-normal-date).

Using my solution on https://emacs.stackexchange.com/questions/43984/convert-between-iso-week-and-a-normal-date, the solution to your first question is found below.

Example:

(iso-header 2018 32)
"** WW32 (Monday August 06 - Sunday August 12, 2018)"
(iso-header 2018 53)
"** WW01 (Monday December 31 - Sunday January 06, 2019)"

(defun iso-header(year week)
  (concat
   (format-time-string "** WW%V (%A %B %d - " (iso-beginning-of-week year week))
   (format-time-string "%A %B %d, %Y)" (iso-end-of-week year week))))
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top