The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>

<body style="background-color: white">



<ul id="index">
  <li><a href="#NAME">NAME</a></li>
  <li><a href="#SYNOPSIS">SYNOPSIS</a></li>
  <li><a href="#DESCRIPTION">DESCRIPTION</a></li>
  <li><a href="#CHANGES">CHANGES</a></li>
  <li><a href="#ISO-8601">ISO 8601</a></li>
  <li><a href="#EXPORT">EXPORT</a>
    <ul>
      <li><a href="#WeekOfYear">WeekOfYear</a></li>
    </ul>
  </li>
  <li><a href="#KNOWN-ISSUES">KNOWN ISSUES</a></li>
  <li><a href="#AUTHOR">AUTHOR</a></li>
  <li><a href="#SEE-ALSO">SEE ALSO</a></li>
  <li><a href="#ACKNOWLEDGEMENTS">ACKNOWLEDGEMENTS</a></li>
  <li><a href="#Log">Log</a>
    <ul>
      <li><a href="#CVS-ID">CVS ID</a></li>
    </ul>
  </li>
</ul>

<h1 id="NAME">NAME</h1>

<p>Date::WeekOfYear - Simple routine to return the ISO 8601 week of the year (as well as the ISO week year)</p>

<h1 id="SYNOPSIS">SYNOPSIS</h1>

<pre><code>  <span class="keyword">use</span> <span class="variable">Date::WeekOfYear</span><span class="operator">;</span>
  
  <span class="comment"># Get the week number (and year for the end/start of year transitions)</span>
  <span class="keyword">my</span> <span class="operator">(</span><span class="variable">$wkNo</span><span class="operator">,</span> <span class="variable">$year</span><span class="operator">)</span> <span class="operator">=</span> <span class="variable">WeekOfYear</span><span class="operator">();</span>
  
  <span class="comment"># Get the week number for the time passed in time_stamp</span>
  <span class="keyword">my</span> <span class="operator">(</span><span class="variable">$wkNo</span><span class="operator">,</span> <span class="variable">$year</span><span class="operator">)</span> <span class="operator">=</span> <span class="variable">WeekOfYear</span><span class="operator">(</span><span class="variable">$time_stamp</span><span class="operator">);</span>
  
  <span class="comment"># Use the data for someThing ...</span>
  <span class="keyword">my</span> <span class="variable">$logFile</span> <span class="operator">=</span> <span class="string">"/someDir/</span><span class="variable">$year</span><span class="string">/someApp_</span><span class="variable">$wkNo</span><span class="string">.log"</span>
  
  <span class="comment"># Only want the week number, don't care which year in the week around</span>
  <span class="comment"># the end/start of the year !</span>
  <span class="keyword">my</span> <span class="variable">$weekNo</span> <span class="operator">=</span> <span class="variable">WeekOfYear</span><span class="operator">();</span>
</code></pre>

<h1 id="DESCRIPTION">DESCRIPTION</h1>

<p>Date::WeekOfYear is small and efficient. The only purpose is to return the week of the year. This can be called in either a scalar or list context.</p>

<p>In a scalar context, just the week number is returned (the year starts at week 1).</p>

<p>In a list context, both the week number and the year (YYYY) are returned. This ensures that you know which year the week number relates too. This is only an issue in the week where the year changes (ie depending on the day you can be in either week 52, week 53 or week 1.</p>

<p><b>NOTE</b> The year returned is not always the same as the Gregorian year for that day for further details see ISO 8601.</p>

<h1 id="CHANGES">CHANGES</h1>

<p>As of version 1.5 the ISO 8601 week number is calculated. For backwards compatibility a flag can be passed after the time to give the previous functionality.</p>

<p>For example:</p>

<pre><code>  <span class="keyword">my</span> <span class="variable">$weekNo</span> <span class="operator">=</span> <span class="variable">WeekOfYear</span><span class="operator">(</span><span class="keyword">undef</span><span class="operator">,</span> <span class="number">1</span><span class="operator">);</span>  <span class="comment"># Week number now in pre ISO 8601 mode</span>
  <span class="keyword">or</span>
  <span class="keyword">my</span> <span class="variable">$weekNo</span> <span class="operator">=</span> <span class="variable">WeekOfYear</span><span class="operator">(</span><span class="variable">$the_time</span><span class="operator">,</span> <span class="number">1</span><span class="operator">);</span>  <span class="comment"># Week number for $the_time in pre ISO 8601 mode</span>
</code></pre>

<h1 id="ISO-8601">ISO 8601</h1>

<p>Weeks in a Gregorian calendar year can be numbered for each year. This style of numbering is commonly used (for example, by schools and businesses) in some European and Asian countries, but rare elsewhere.</p>

<p>ISO 8601 includes the ISO week date system, a numbering system for weeks - each week begins on a Monday and is associated with the year that contains that week&#39;s Thursday (so that if a year starts in a long weekend Friday-Sunday, week number one of the year will start after that). For example, week 1 of 2004 (2004W01) ran from Monday 29 December 2003 to Sunday, 4 January 2004, because its Thursday was 1 January 2004, whereas week 1 of 2005 (2005W01) ran from Monday 3 January 2005 to Sunday 9 January 2005, because its Thursday was 6 January 2005 and so the first Thursday of 2005. The highest week number in a year is either 52 or 53 (it was 53 in the year 2004).</p>

<p>An ISO week-numbering year (also called ISO year informally) has 52 or 53 full weeks. That is 364 or 371 days instead of the usual 365 or 366 days. The extra week is referred to here as a leap week, although ISO 8601 does not use this term. Weeks start with Monday. The first week of a year is the week that contains the first Thursday (and, hence, 4 January) of the year. ISO week year numbering therefore slightly deviates from the Gregorian for some days close to 1 January.</p>

<h1 id="EXPORT">EXPORT</h1>

<h2 id="WeekOfYear">WeekOfYear</h2>

<p>WeekOfYear. That&#39;s it, nice and simple</p>

<h1 id="KNOWN-ISSUES">KNOWN ISSUES</h1>

<p><b>Versions prior to 1.5 did not follow ISO 8601.</b></p>

<p>None, however please contact the author at gng@cpan.org should you find any problems and I will endevour to resolve then as soon as possible.</p>

<h1 id="AUTHOR">AUTHOR</h1>

<pre><code> Greg George, IT Technology Solutions P/L, Australia
 Mobile: +61-404-892-159, Email: gng@cpan.org</code></pre>

<h1 id="SEE-ALSO">SEE ALSO</h1>

<p>Date::Parse or check CPAN http://search.cpan.org/search?query=Date&amp;mode=all</p>

<h1 id="ACKNOWLEDGEMENTS">ACKNOWLEDGEMENTS</h1>

<p>Thanks to Alexandr Ciornii for the V1.3 updates Thanks to Niel Bowers for [rt.cpan.org #93599] Not clear what type of week number is returned</p>

<h1 id="Log">Log</h1>

<p>Revision 1.5 2014/03/16 Greg - Updated to conform to ISO 8601 - Added compatability flag to allow backwards usage</p>

<p>Revision 1.4 2009/06/21 07:29:05 Greg - Added ACKNOWLEDGEMENTS</p>

<p>Revision 1.3 2009/06/20 09:31:39 Greg - Real tests with Test::More - Tests moved to t/ - Better Makefile.PL - Now WeekOfYear can take an argument (unixtime)</p>

<p>Revision 1.2 2006/06/11 02:28:55 Greg - Correction to name of function</p>

<p>Revision 1.1.1.1 2004/08/09 11:07:15 Greg - Initial release to CPAN</p>

<h2 id="CVS-ID">CVS ID</h2>

<p>$Id: WeekOfYear.pm,v 1.4 2009/06/21 07:29:05 Greg Exp $</p>


</body>

</html>