week number definition for Linux ?

This is a discussion on week number definition for Linux ? within the Linux Programming forums, part of the Platform Specific Boards category; Hi all, I have a question about how week number should be defined/counted (in Linux) in terms of week number ...

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    16

    Red face week number definition for Linux ?

    Hi all,

    I have a question about how week number should be defined/counted (in Linux) in terms of week number of a year and week number of a month.

    For instance, 2011-01-07:
    Code:
    January 2011
    
    Su	Mo	Tu	We	Th	Fr	Sa
     	 	 	 	 	 	1
    2	3	4	5	6	7	8
    9	10	11	12	13	14	15
    16	17	18	19	20	21	22
    23	24	25	26	27	28	29
    30	31
    It is in the week 1 of the year 2011 which obtained by using
    Code:
     size_t strftime ( char * ptr, size_t maxsize, const char * format, const struct tm * timeptr );
    and printf the value of %U of the given struct tm for 2011-01-07 .

    However, I am not sure 2011-01-07 is considered to be in the week #1 or week #2 of the month. What would be the right value?

    I need to know the correct week number of the month because it will be used to set TZ env as CST+6CDT,M4.1.0/2,M10.5.0/2 for daylight saving time. and the number in Bold above is the week number in month needed to be specified.

    Could you kindly offer your comments on this.
    Thanks in advance. :-)

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,761
    Read the man page for strftime(), and see which format matches your idea of week numbers.
    %u The day of the week as a decimal, range 1 to 7, Monday being 1. See also %w. (SU)

    %U The week number of the current year as a decimal number, range 00 to 53, starting with the first Sunday as the first day of week 01. See also
    %V and %W.

    %V The ISO 8601 week number (see NOTES) of the current year as a decimal number, range 01 to 53, where week 1 is the first week that has at least
    4 days in the new year. See also %U and %W. (SU)

    %w The day of the week as a decimal, range 0 to 6, Sunday being 0. See also %u.

    %W The week number of the current year as a decimal number, range 00 to 53, starting with the first Monday as the first day of week 01.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Who are the people who are defining your date format? They are the ones you should be asking.

  4. #4
    Registered User
    Join Date
    Dec 2009
    Posts
    16
    Never mind. :-)

    %U: Week number with the first Sunday as the first day of week one (00-53), so the return value 1 actually means week #2.
    I think that is the expected week number to be used.

  5. #5
    Registered User
    Join Date
    Dec 2009
    Posts
    16
    Got it. Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Is there's a number in windows like inode in linux?
    By Ocean_Sky in forum Windows Programming
    Replies: 2
    Last Post: 08-20-2010, 10:08 AM
  2. Equivalent to volume serial number in linux
    By Elkvis in forum Linux Programming
    Replies: 8
    Last Post: 06-30-2009, 09:46 PM
  3. Allocation of major number and minor number linux
    By vinayharitsakp@ in forum Linux Programming
    Replies: 4
    Last Post: 12-08-2007, 02:01 PM
  4. Number of words multiplied by the number of lines in Linux
    By sjalesho in forum Linux Programming
    Replies: 2
    Last Post: 11-20-2003, 03:25 PM
  5. e-week, networking, and a 96 hour week...
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 02-23-2003, 05:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21