PHP: Get date for nth occurrence of weekday

PHP: Get date for nth occurrence of weekday

I looked quickly and did not see any code out there to determine the nth occurrence of a specific day of the week in a month.  For example Thanksgiving is the 4th Thursday in November.  So I designed the following

<?php
$year = 2012; 
//Pick your year
$interval = 4; 
//Week number, in this case the 4th week
$dayofweek = 4; 
//Day of week 0=Sun, 1=Mon. . .
$month = 11; 
//Month 1=Jan, 2=Feb

$firstday = jddayofweek(gregoriantojd($month, 1, $year), 0);
if($firstday <= $dayofweek){
  $date = (($interval * 7)-6) + ($dayofweek - $firstday);
}else{
  $date = (($interval * 7)-1) + (6 - $firstday);
}
echo date("n/j/Y", mktime(0, 0, 0, $month, $date, $year));
?>

It looks a little messy, but it works perfectly.

 

UPDATE:

So apparently as bad as this looks it works too:

Read More Read More

Bug in BlackBerry Repeat Rule, MONTH_OF_YEAR Deincrements 1 Month

Bug in BlackBerry Repeat Rule, MONTH_OF_YEAR Deincrements 1 Month

I have noticed a bug in javax.microedition.pim.RepeatRule, when I tried to set a an event to repeat every second sunday of may I would get an event that repeated every second sunday of april. I determined that this was being caused by MONTH_OF_YEAR being deincremented by 1 month after the event was committed.

I worked around the problem by setting the value one month forward. However obviously, this does not work for december. I tried increasing the value of the MONTH_OF_YEAR setting, however java balks at any unknown value. Currently I am unable to set an event to occur on the second sunday in december. If anyone figures out a work around I would be greatful.

RIM has recognized that this is a bug, but who knows when the bug will be fixed. I attached a copy of the email I received from RIM:

Read More Read More

Blackberry IMAP Proxy – Working Sent and Trash Folders

Blackberry IMAP Proxy – Working Sent and Trash Folders

RIM has never fully supported IMAP servers in their Blackberry Internet Service(BIS) formerly Blackberry Web Client(BWC). Notably BIS does not recognize the NAMESPACE command from IMAP servers. The vast majority of IMAP servers place all user folders in a single parent folder(usually INBOX) therefore the Sent and Trash folders are actually INBOX.Sent and INBOX.Trash. Unfortunately BIS only recognizes Sent and Trash in the base directory.

This script sits between the BIS and your IMAP server. The proxy then makes INBOX.Sent and INBOX.Trash appear to be Sent and Trash. This enables BIS to save a copy of your sent emails into INBOX.Sent properly and a copy of deleted emails into INBOX.Trash properly.

Additionally this script allows you to use a non standard folder as your inbox as well.

Read More Read More

Patio Plant Watering System

Patio Plant Watering System

I want to have plants on my balcony, but I knew I would be incapable of watering the plants everyday. Clearly I needed an automatic watering system, however, I live on the 5th floor and have no access to water on my patio.

I saw an automatic watering system like this. But it was just too much money and it didn’t hold nearly enough water. So, I decided to make my own watering system that could hold a lot more water. I was able to make a 5 gallon system for less than $30.

Read More Read More

pyTivo – Aspect Ratio

pyTivo – Aspect Ratio

I have received a number of questions about how pyTivo handles aspect ratios.  Aspect ratios are a very convoluted subject as you will see.  I make no attempt to explain everything, at the end of this page you will see a link to a much longer page that does a better explanation than me.

This is meant to be a quick and dirty explanation of how pyTivo handles Aspect Ratios.

Quick Tutorial on Aspect Ratios By no means is any of this guaranteed to be accurate. This only represents what I believe to be true, if I am making a mistake that causes an error in pyTivo please point it out to me.

There are two types of aspect ratios:
Frame Aspect Ratio
This is simply the ratio of what the file looks like when it plays on your TV which can be determined by:
Width displayed on TV: Height displayed on TV. TiVo accepts files in 16:9 or 4:3 format.

Pixel Aspect Ratio
This is the annoying one. This refers to the shape of the pixels themselves. For example a 1:1 pixel aspect ratio means a perfect square pixel.

Most computer files are saved in 1:1 Pixel Aspect Ratio(PAR) however that is where it ends.  TV, DVD, Film is all distorted to some other PAR.  Infortunately there is no way for us to know when pyTivo opens a file what the PAR is.  For the most part since pyTivo is using computer files it assumes that most files are 1:1.  And then if the file fits an exact dimension of a known non 1:1 PAR pyTivo will use that dimension.

Oh but we are not done. . .

Read More Read More