unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Week number
@ 2008-10-14  6:25 Xavier Maillard
  2008-10-14 13:08 ` Paul R
  0 siblings, 1 reply; 14+ messages in thread
From: Xavier Maillard @ 2008-10-14  6:25 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

I can't find anything in GNU Emacs (CVS). I need a function that
would return a formated week number (merely "%yw%w") given a date
(or the current week number if no date given as argument).

Does anybody have this ?

	Xavier
-- 
http://www.gnu.org
http://www.april.org
http://www.lolica.org




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Week number
       [not found] <mailman.994.1223980354.25473.help-gnu-emacs@gnu.org>
@ 2008-10-14 12:43 ` Charles Sebold
  2008-10-14 12:53   ` Charles Sebold
  0 siblings, 1 reply; 14+ messages in thread
From: Charles Sebold @ 2008-10-14 12:43 UTC (permalink / raw)
  To: help-gnu-emacs

On 14 Oct 2008, Xavier Maillard wrote:

> I can't find anything in GNU Emacs (CVS). I need a function that
> would return a formated week number (merely "%yw%w") given a date
> (or the current week number if no date given as argument).

Here's how org-mode does it:

(defun org-days-to-iso-week (days)
  "Return the iso week number."
  (require 'cal-iso)
  (car (calendar-iso-from-absolute days)))
-- 
Charles Sebold                                     14th of October, 2008


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Week number
  2008-10-14 12:43 ` Charles Sebold
@ 2008-10-14 12:53   ` Charles Sebold
  2008-10-14 20:25     ` Xavier Maillard
       [not found]     ` <mailman.1043.1224016162.25473.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 14+ messages in thread
From: Charles Sebold @ 2008-10-14 12:53 UTC (permalink / raw)
  To: help-gnu-emacs

On 14 Oct 2008, Charles Sebold wrote:

> Here's how org-mode does it:

Sorry, this is really what you were asking for, then:

(defun crs-iso-week (&optional date)
  "Week number of ISO date of Gregorian DATE.
Defaults to today's date if DATE is not given."
  (require 'cal-iso)
  (let* ((d (calendar-absolute-from-gregorian
             (or date (calendar-current-date))))
         (iso-date (calendar-iso-from-absolute d)))
    (format "%dw%2d" (extract-calendar-year iso-date)
            (extract-calendar-month iso-date))))
-- 
Charles Sebold                                     14th of October, 2008


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Week number
  2008-10-14  6:25 Week number Xavier Maillard
@ 2008-10-14 13:08 ` Paul R
  2008-10-14 20:25   ` Xavier Maillard
  0 siblings, 1 reply; 14+ messages in thread
From: Paul R @ 2008-10-14 13:08 UTC (permalink / raw)
  To: Xavier Maillard; +Cc: help-gnu-emacs

> Does anybody have this ?

(format-time-string "%W")

For more info, C-h f format-time-string

-- 
  Paul




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Week number
  2008-10-14 13:08 ` Paul R
@ 2008-10-14 20:25   ` Xavier Maillard
  0 siblings, 0 replies; 14+ messages in thread
From: Xavier Maillard @ 2008-10-14 20:25 UTC (permalink / raw)
  To: Paul R; +Cc: help-gnu-emacs


   > Does anybody have this ?

   (format-time-string "%W")

   For more info, C-h f format-time-string

Thank you. I should have read the format-time-string description
more carefully.

	Xavier
-- 
http://www.gnu.org
http://www.april.org
http://www.lolica.org




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Week number
  2008-10-14 12:53   ` Charles Sebold
@ 2008-10-14 20:25     ` Xavier Maillard
  2008-10-14 21:13       ` Charles Sebold
  2008-10-14 21:37       ` Peter Dyballa
       [not found]     ` <mailman.1043.1224016162.25473.help-gnu-emacs@gnu.org>
  1 sibling, 2 replies; 14+ messages in thread
From: Xavier Maillard @ 2008-10-14 20:25 UTC (permalink / raw)
  To: Charles Sebold; +Cc: help-gnu-emacs

Hi,

   On 14 Oct 2008, Charles Sebold wrote:

   > Here's how org-mode does it:

   Sorry, this is really what you were asking for, then:

   (defun crs-iso-week (&optional date)

Thank you very much.

I have a question though.

I compared the results of your function and the result from a
simple (format-time-string "%W") for the current date and I got
week 42 for the former and week 41 for the latter. Can you
explain this ?

Regards

	Xavier
-- 
http://www.gnu.org
http://www.april.org
http://www.lolica.org




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Week number
       [not found]     ` <mailman.1043.1224016162.25473.help-gnu-emacs@gnu.org>
@ 2008-10-14 21:09       ` Charles Sebold
  2008-10-14 21:56         ` Drew Adams
  2008-10-15 21:28       ` Harald Hanche-Olsen
  1 sibling, 1 reply; 14+ messages in thread
From: Charles Sebold @ 2008-10-14 21:09 UTC (permalink / raw)
  To: help-gnu-emacs

On 14 Oct 2008, Xavier Maillard wrote:

> I compared the results of your function and the result from a
> simple (format-time-string "%W") for the current date and I got
> week 42 for the former and week 41 for the latter. Can you
> explain this ?

No, I can't.  Unless you could try it with the date for 1 January and
see if you get week "0" or week "1" with each; maybe that's the
problem.

What I see here suggests that 42 is correct:

http://en.wikipedia.org/wiki/ISO_8601
-- 
Charles Sebold                                     14th of October, 2008


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Week number
  2008-10-14 20:25     ` Xavier Maillard
@ 2008-10-14 21:13       ` Charles Sebold
  2008-10-14 21:37       ` Peter Dyballa
  1 sibling, 0 replies; 14+ messages in thread
From: Charles Sebold @ 2008-10-14 21:13 UTC (permalink / raw)
  To: Xavier Maillard; +Cc: help-gnu-emacs, Charles Sebold

On 14 Oct 2008, Xavier Maillard wrote:

> I compared the results of your function and the result from a
> simple (format-time-string "%W") for the current date and I got
> week 42 for the former and week 41 for the latter. Can you
> explain this ?

However, looking at this more closely, I think that maybe it's a
question of whether you want ISO weeks or not.  It's a thornier problem
than I first realized.

http://en.wikipedia.org/wiki/ISO_week_date
-- 
Charles Sebold
http://merbc.invigorated.org/
http://triablogue.blogspot.com/




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Week number
  2008-10-14 20:25     ` Xavier Maillard
  2008-10-14 21:13       ` Charles Sebold
@ 2008-10-14 21:37       ` Peter Dyballa
  2008-10-14 21:42         ` Charles Sebold
  1 sibling, 1 reply; 14+ messages in thread
From: Peter Dyballa @ 2008-10-14 21:37 UTC (permalink / raw)
  To: Xavier Maillard; +Cc: help-gnu-emacs, Charles Sebold


Am 14.10.2008 um 22:25 schrieb Xavier Maillard:

> I compared the results of your function and the result from a
> simple (format-time-string "%W") for the current date and I got
> week 42 for the former and week 41 for the latter. Can you
> explain this ?

On the command line 'date +%W' returns 41 – although here in Germany  
it's already 42nd week ... This number is displayed by 'date +%V'. My  
documentation says:

      %V    is replaced by the week number of the year (Monday as the  
first day
            of the week) as a decimal number (01-53).  If the week  
containing
            January 1 has four or more days in the new year, then it  
is week 1;
            otherwise it is the last week of the previous year, and  
the next
            week is week 1.

      %W    is replaced by the week number of the year (Monday as the  
first day
            of the week) as a decimal number (00-53).

So %W counts the complete weeks and %V counts the legal weeks. And  
(format-time-string "%V") returns 42 for me. See also 'man strftime'.

--
Greetings

   Pete

The world would be a better place if Larry Wall had been born in  
Iceland, or any other country where the native language actually has  
syntax.
				– Peter da Silva







^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Week number
  2008-10-14 21:37       ` Peter Dyballa
@ 2008-10-14 21:42         ` Charles Sebold
  2008-10-15  8:25           ` Xavier Maillard
  0 siblings, 1 reply; 14+ messages in thread
From: Charles Sebold @ 2008-10-14 21:42 UTC (permalink / raw)
  To: Peter Dyballa; +Cc: help-gnu-emacs, Charles Sebold

On 14 Oct 2008, Peter Dyballa wrote:

> So %W counts the complete weeks and %V counts the legal weeks. And
> (format-time-string "%V") returns 42 for me. See also 'man strftime'.

Good to know both possibilities are covered.  Forget my function, then.
-- 
Charles Sebold
http://merbc.invigorated.org/
http://triablogue.blogspot.com/




^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: Week number
  2008-10-14 21:09       ` Charles Sebold
@ 2008-10-14 21:56         ` Drew Adams
  2008-10-15  8:25           ` Xavier Maillard
  0 siblings, 1 reply; 14+ messages in thread
From: Drew Adams @ 2008-10-14 21:56 UTC (permalink / raw)
  To: 'Charles Sebold', help-gnu-emacs

> What I see here suggests that 42 is correct:

According to THHGTTG, 42 is the answer.





^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Week number
  2008-10-14 21:56         ` Drew Adams
@ 2008-10-15  8:25           ` Xavier Maillard
  0 siblings, 0 replies; 14+ messages in thread
From: Xavier Maillard @ 2008-10-15  8:25 UTC (permalink / raw)
  To: Drew Adams; +Cc: help-gnu-emacs, csebold


   > What I see here suggests that 42 is correct:

   According to THHGTTG, 42 is the answer.

There could not be another answer :)

	Xavier
-- 
http://www.gnu.org
http://www.april.org
http://www.lolica.org




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Week number
  2008-10-14 21:42         ` Charles Sebold
@ 2008-10-15  8:25           ` Xavier Maillard
  0 siblings, 0 replies; 14+ messages in thread
From: Xavier Maillard @ 2008-10-15  8:25 UTC (permalink / raw)
  To: Charles Sebold; +Cc: Peter_Dyballa, help-gnu-emacs


   On 14 Oct 2008, Peter Dyballa wrote:

   > So %W counts the complete weeks and %V counts the legal weeks. And
   > (format-time-string "%V") returns 42 for me. See also 'man strftime'.

   Good to know both possibilities are covered.  Forget my function, then.

Yes. Anyway thank you very much.

	Xavier
-- 
http://www.gnu.org
http://www.april.org
http://www.lolica.org




^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Week number
       [not found]     ` <mailman.1043.1224016162.25473.help-gnu-emacs@gnu.org>
  2008-10-14 21:09       ` Charles Sebold
@ 2008-10-15 21:28       ` Harald Hanche-Olsen
  1 sibling, 0 replies; 14+ messages in thread
From: Harald Hanche-Olsen @ 2008-10-15 21:28 UTC (permalink / raw)
  To: help-gnu-emacs

+ Xavier Maillard <xma@gnu.org>:

> I compared the results of your function and the result from a
> simple (format-time-string "%W") for the current date and I got
> week 42 for the former and week 41 for the latter. Can you
> explain this ?

There are different ways to count week numbers. You can bet that any
function having -iso- in its name will use ISO week numbering, which
corresponds to %V, not to %W. Here are the relevant bits from the
strftime man page on freebsd.

     %U    is replaced by the week number of the year (Sunday as the first day
           of the week) as a decimal number (00-53).

     %V    is replaced by the week number of the year (Monday as the first day
           of the week) as a decimal number (01-53).  If the week containing
           January 1 has four or more days in the new year, then it is week 1;
           otherwise it is the last week of the previous year, and the next
           week is week 1.

     %W    is replaced by the week number of the year (Monday as the first day
           of the week) as a decimal number (00-53).

(Note also that the proper way to write the week the ISO way is %GW%V,
not %YW%V as you might think.)

-- 
* Harald Hanche-Olsen     <URL:http://www.math.ntnu.no/~hanche/>
- It is undesirable to believe a proposition
  when there is no ground whatsoever for supposing it is true.
  -- Bertrand Russell


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2008-10-15 21:28 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-14  6:25 Week number Xavier Maillard
2008-10-14 13:08 ` Paul R
2008-10-14 20:25   ` Xavier Maillard
     [not found] <mailman.994.1223980354.25473.help-gnu-emacs@gnu.org>
2008-10-14 12:43 ` Charles Sebold
2008-10-14 12:53   ` Charles Sebold
2008-10-14 20:25     ` Xavier Maillard
2008-10-14 21:13       ` Charles Sebold
2008-10-14 21:37       ` Peter Dyballa
2008-10-14 21:42         ` Charles Sebold
2008-10-15  8:25           ` Xavier Maillard
     [not found]     ` <mailman.1043.1224016162.25473.help-gnu-emacs@gnu.org>
2008-10-14 21:09       ` Charles Sebold
2008-10-14 21:56         ` Drew Adams
2008-10-15  8:25           ` Xavier Maillard
2008-10-15 21:28       ` Harald Hanche-Olsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).