And one of many possible solutions.

$weeks = myDateTimeTools::getWeeksOfMonth($month, $year);

class myDateTimeTools
{
 public static function getWeeksOfMonth($month = null, $year = null)
 {
   if (!$month) $month = date('m');
   if (!$year) $year = date('Y');

   $dt = sfDate::getInstance($year.'-'.$month.'-01')->subtractMonth()-
>finalDayOfMonth()->addWeek()->firstDayOfWeek();
   $base = sfDate::getInstance($year.'-'.$month.'-01')-
>finalDayOfMonth();

   $ar = array();
   while ($dt->cmp($base) < 0)
   {
     $ar[] = $dt->get();
     $dt->addWeek();
   }

   return $ar;
 }
}

Or you can use the <code>setMonth</code> and <code>setYear</code>
functions.  <code>$dt = new sfDate(); $dt->setMonth($month); $dt-
>setYear($year);</code>.

On Feb 21, 9:08 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> I am trying to extend the sfDate ()  plugin  for a project.
>
> After a great email tip from the original author, I have:
> class myDate
> {
>
>  public static function getWeeksOfMonth($ts = null)
>  {
>
>         if ($ts === null) $ts = sfDateTimeToolkit::now();
>
>   $dt = 
> sfDate::getInstance()->subtractMonth()->finalDayOfMonth()->addWeek()->firstDayOfWeek($ts);
>
>   $base = sfDate::getInstance()->finalDayOfMonth($ts);
>   $ar = array();
>   while ($dt->cmp($base) < 0)
>   {
>     $ar[] = $dt->get();
>     $dt->addWeek();
>   }
>
>   return $ar;
>  }
>
> }
>
> my problem is that I cant get it to recognize $ts, and thus  only does
> current month.
>
> any ideas?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to