<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Error Message</title>
	<atom:link href="http://www.theerrormessage.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.theerrormessage.com</link>
	<description>Fix your error</description>
	<lastBuildDate>Wed, 25 Apr 2012 13:46:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Slow ssh and slow vsftpd login &#8211; Centos 6</title>
		<link>http://www.theerrormessage.com/2011/12/slow-ssh-and-slow-vsftpd-login-centos-6/</link>
		<comments>http://www.theerrormessage.com/2011/12/slow-ssh-and-slow-vsftpd-login-centos-6/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 20:11:50 +0000</pubDate>
		<dc:creator>gbl</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Centos]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[sshd]]></category>
		<category><![CDATA[vsftpd]]></category>

		<guid isPermaLink="false">http://www.theerrormessage.com/?p=333</guid>
		<description><![CDATA[The reason that the ssh commands were slow and sluggish (had to wait for seconds after enter was pressed to execute the command). There was nothing in the logs (that I could find) to help me identify this issue. I used google and many ideas from different forums without any luck. I discovered that the [...]]]></description>
			<content:encoded><![CDATA[<p>The reason that the ssh commands were slow and sluggish (had to wait for seconds after enter was pressed to execute the command). There was nothing in the logs (that I could find) to help me identify this issue. I used google and many ideas from different forums without any luck.</p>
<p>I discovered that the changes I did to iptables some time before were wrong. Being a newbie I removed a rule that seamed suspicious (to me this rule looked too permissive):</p>
<p><code>ACCEPT     all  --  anywhere             anywhere</code></p>
<p>To fix the issue I added the following rule back to my iptables. &#8220;This rule will allow all incoming packets destined for the localhost interface to be accepted.&#8221;</p>
<p><code>iptables -A INPUT -i lo -j ACCEPT</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.theerrormessage.com/2011/12/slow-ssh-and-slow-vsftpd-login-centos-6/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to move Winamp playlist entries fast to the begining or the end of the list when having a long playlist</title>
		<link>http://www.theerrormessage.com/2011/06/how-to-move-playlist-entries-fast-to-the-begining-or-the-end-of-the-list-when-having-a-long-playlist/</link>
		<comments>http://www.theerrormessage.com/2011/06/how-to-move-playlist-entries-fast-to-the-begining-or-the-end-of-the-list-when-having-a-long-playlist/#comments</comments>
		<pubDate>Mon, 13 Jun 2011 00:11:51 +0000</pubDate>
		<dc:creator>thalissar</dc:creator>
				<category><![CDATA[How to]]></category>

		<guid isPermaLink="false">http://www.theerrormessage.com/?p=326</guid>
		<description><![CDATA[Selecting the Winamp entries: 1. Click on one entry in the list that you want to move. 2. If you want to move several entries, you can select them in one of the following ways: - to select a block of entries starting with the entry chosen at step 1 (onwards/backwards from that entry): SHIFT [...]]]></description>
			<content:encoded><![CDATA[<p>Selecting the Winamp entries:<br />
1. Click on one entry in the list that you want to move.<br />
2. If you want to move several entries, you can select them in one of the following ways:<br />
- to select a block of entries starting with the entry chosen at step 1 (onwards/backwards from that entry):<br />
SHIFT + left mouse button click on the last entry to be moved<br />
or<br />
SHIFT + up/down arrow<br />
- to select non consecutive entries including the entry chosen at step 1: CTRL + left mouse button click on every other entry to be moved.</p>
<p>Moving the selected entries to the begining/end of the Winamp playlist:<br />
1. Left mouse button click and hold on one of the selected entries and press HOME/END key on the keyboard so that you end up on the first/last page of the playlist. Don&#8217;t release the mouse button!<br />
2. Drag the selection with the mouse to the very begining/end of the playlist.</p>
<p>Enjoy your audition!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.theerrormessage.com/2011/06/how-to-move-playlist-entries-fast-to-the-begining-or-the-end-of-the-list-when-having-a-long-playlist/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP isset() function returns FALSE even though the variable is defined</title>
		<link>http://www.theerrormessage.com/2011/01/php-isset-function-returns-false-even-though-the-variable-is-defined/</link>
		<comments>http://www.theerrormessage.com/2011/01/php-isset-function-returns-false-even-though-the-variable-is-defined/#comments</comments>
		<pubDate>Fri, 14 Jan 2011 22:58:31 +0000</pubDate>
		<dc:creator>thalissar</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.theerrormessage.com/?p=307</guid>
		<description><![CDATA[Let&#8217;s say we have a table item in a MySQL database, with the primary key iditem and a field code that can be NULL: CREATE TABLE `item` ( `iditem` int(10) unsigned NOT NULL, `code` VARCHAR(10) DEFAULT NULL, PRIMARY KEY (`iditem`), ); -- -- Dumping data for table `item` -- INSERT INTO `item` (`iditem`, `code`) VALUES [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s say we have a table <em>item</em> in a MySQL database, with the primary key <em>iditem</em> and a field <em>code</em> that can be NULL:</p>
<pre class="code brush:sql">CREATE TABLE `item` (
`iditem` int(10) unsigned NOT NULL,
`code` VARCHAR(10) DEFAULT NULL,
PRIMARY KEY (`iditem`),
);

--
-- Dumping data for table `item`
--

INSERT INTO `item` (`iditem`, `code`) VALUES
(1, 'as1435v'),
(2, NULL),
(3, 1, 'YHryt4t90');</pre>
<p>In PHP we define a variable <em>$item_code</em> that we initialize with 0 and then we run a query for setting the value of <em>$item_code</em> to the code of the item which has the id 2 in our database:</p>
<pre class="code brush:php">$item_code = 0;
$query = "SELECT code FROM item WHERE iditem = 2";
$result = mysql_query($conn); //$conn is our database connection
if($result) {
	if($row = mysql_fetch_row($result)) {
		$item_code = $row[0];
	}
}

if(isset($item_code)) {
	echo "item code: ".$item_code;
} else {
	echo "item code is not set";
}</pre>
<p>The output will be:<br />
<em>item code is not set</em></p>
<p>That is because the code is NULL in the database and it is transferred into PHP not as the empty string, but as NULL.<br />
And the name of the isset() function is misleading as it returns FALSE not only when a variable is not defined, but also when a variable has been set to NULL.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.theerrormessage.com/2011/01/php-isset-function-returns-false-even-though-the-variable-is-defined/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Strange empty text line appearing inside my page</title>
		<link>http://www.theerrormessage.com/2011/01/strange-empty-text-line-appearing-inside-my-page/</link>
		<comments>http://www.theerrormessage.com/2011/01/strange-empty-text-line-appearing-inside-my-page/#comments</comments>
		<pubDate>Fri, 14 Jan 2011 00:58:35 +0000</pubDate>
		<dc:creator>gbl</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.theerrormessage.com/?p=198</guid>
		<description><![CDATA[Usually you see an empty text line and you look at the source and you see nothing there just a space&#8230; That happens often when the files that are outputted are using the encoding UTF8 with signature, instead of using the correct encoding UTF8 without signature.]]></description>
			<content:encoded><![CDATA[<p>Usually you see an empty text line and you look at the source and you see nothing there just a space&#8230;</p>
<p>That happens often when the files that are outputted are using the encoding UTF8 with signature, instead of using the correct encoding UTF8 without signature.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.theerrormessage.com/2011/01/strange-empty-text-line-appearing-inside-my-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Delayed javascript function/handler gets the right variable/parameter values</title>
		<link>http://www.theerrormessage.com/2011/01/delayed-javascript-functionhandler-gets-the-right-parameter-values/</link>
		<comments>http://www.theerrormessage.com/2011/01/delayed-javascript-functionhandler-gets-the-right-parameter-values/#comments</comments>
		<pubDate>Thu, 13 Jan 2011 23:22:39 +0000</pubDate>
		<dc:creator>gbl</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.theerrormessage.com/?p=286</guid>
		<description><![CDATA[So we have a function that adds a handler function that is called after an ajax load or at a later time and we need to execute the handler function code for each item inside an array allowing the function to access the array values. Usually with the simplest try you would get some code [...]]]></description>
			<content:encoded><![CDATA[<p>So we have a function that adds a handler function that is called after an ajax load or at a later time and we need to execute the handler function code for each item inside an array allowing the function to access the array values. Usually with the simplest try you would get some code that get&#8217;s executed with invalid variable values. Examples are below.</p>
<p>The wrong code:</p>
<pre class="code brush:javascript">
//the function that will do the stuff for each array
var dostuff = function (arr) {
var n = arr.length,
    i;
    for(i = 0; i < n; i++) {
        var o = arr[i];
        //event bind or delayed function call
        setTimeout(function () {
                //we want to access here the correct arr[i]
                //when the code gets here the value of o is arr[arr.length-1]
                console.log(o);
        }, 1000);
    }
}
dostuff([1,2,3,4]);
</pre>
<p>You can load the code into your javascript console to see it in action.<br />
The output appears after 1 second and it is like this:</p>
<pre class="code brush:text">
4
4
4
4
</pre>
<p>I don't need that. I need something that works so we need to wrap the handler call into a function call that will pass the current values as parameters.</p>
<pre class="code brush:javascript">
var dostuff = function (arr) {
var n = arr.length,
    i;
    for(i = 0; i < n; i++) {
        var o = arr[i];
        (function (y) {
            setTimeout(function () {
                console.log(y);
            }, 1000);
        }) (o);
    }
}
dostuff([1,2,3,4]);
</pre>
<p>The output appears after 1 second and it is like this:</p>
<pre class="code brush:text">
1
2
3
4
</pre>
<p>The final best solution would be to have the function inside for already defined so you don't define it on every loop:</p>
<pre class="code brush:javascript">
var dostuff_item = function (y) {
            setTimeout(function () {
                console.log(y);
         }, 1000);
 }
var dostuff = function (arr) {
var n = arr.length,
    i;
    for(i = 0; i < n; i++) {
        var o = arr[i];
        dostuff_item (o);
    }
}
dostuff([1,2,3,4]);
</pre>
<p>Tada!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.theerrormessage.com/2011/01/delayed-javascript-functionhandler-gets-the-right-parameter-values/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updating multiple fields in multiple rows with different values in a single query in MySQL using the CASE operator does not supply a correct result</title>
		<link>http://www.theerrormessage.com/2010/07/updating-multiple-fields-in-multiple-rows-with-different-values-in-a-single-query-in-mysql-using-the-case-operator-does-not-supply-a-correct-result/</link>
		<comments>http://www.theerrormessage.com/2010/07/updating-multiple-fields-in-multiple-rows-with-different-values-in-a-single-query-in-mysql-using-the-case-operator-does-not-supply-a-correct-result/#comments</comments>
		<pubDate>Sun, 18 Jul 2010 03:21:10 +0000</pubDate>
		<dc:creator>thalissar</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.theerrormessage.com/?p=205</guid>
		<description><![CDATA[Suppose we have a table with rows representing nodes of a tree structure, each node being represented by an id, a parent id and a position between the children of its parent node: CREATE TABLE `tree`.`node` ( `idnode` TINYINT NOT NULL AUTO_INCREMENT , `idnode_parent` TINYINT NULL , `position` TINYINT NULL , PRIMARY KEY ( `idnode` [...]]]></description>
			<content:encoded><![CDATA[<p>Suppose we have a table with rows representing nodes of a tree structure, each node being represented by an id, a parent id and a position between the children of its parent  node:</p>
<pre class="code brush:sql">CREATE TABLE  `tree`.`node` (
`idnode` TINYINT NOT NULL AUTO_INCREMENT ,
`idnode_parent` TINYINT NULL ,
`position` TINYINT NULL ,
PRIMARY KEY ( `idnode` )
);</pre>
<p>The nodes with <em>idnode_parent</em> set to 0 or NULL are on the first level of the tree structure.</p>
<p>Now we populate the table:</p>
<pre class="code brush:sql">#add some first level nodes
INSERT INTO `tree`.`node` VALUES (NULL, 0, 1); #idnode = 1
INSERT INTO `tree`.`node` VALUES (NULL, 0, 2); #idnode = 2
#add some children for the first node on the first level
INSERT INTO `tree`.`node` VALUES (NULL, 1, 1); #idnode = 3
INSERT INTO `tree`.`node` VALUES (NULL, 1, 2); #idnode = 4
#add some children for the node with idnode 2
INSERT INTO `tree`.`node` VALUES (NULL, 2, 1); #idnode = 5
INSERT INTO `tree`.`node` VALUES (NULL, 2, 2); #idnode = 6
INSERT INTO `tree`.`node` VALUES (NULL, 2, 3); #idnode = 7
#add a child for the node with idnode 7
INSERT INTO `tree`.`node` VALUES (NULL, 7, 1); #idnode = 8</pre>
<p>Now the table looks like this:<br />
idnode	idnode_parent	position<br />
1		0		1<br />
2		0		2<br />
3		1		1<br />
4		1		2<br />
5		2		1<br />
6		2		2<br />
7		2		3<br />
8		3		1<br />
9		7		1</p>
<p>We want to delete:<br />
- node 1, so we move its children (3, 4) up one level (<em>idnode_parent</em> changes from 1 to 0) and update their positions to the position of their parent (<em>position</em> changes from 1, 2 respectively to 1);<br />
- node 7, so we move its children (8) up one level (<em>idnode_parent</em> changes from 7 to 2) and update their positions to the position of their parent (<em>position</em> changes from 1 to 3)</p>
<p>a) We try this query:</p>
<pre class="code brush:sql">UPDATE node
SET idnode_parent = CASE(idnode_parent)
WHEN 1 THEN 0
WHEN 7 THEN 2
END,
position = CASE(idnode_parent)
WHEN 1 THEN 1
WHEN 7 THEN 3
END
WHERE idnode_parent IN (1, 7);</pre>
<p>Running this query, MySQL says 3 rows were affectedand the table looks as follows:</p>
<p>idnode	idnode_parent	position<br />
1		0		1<br />
2		0		2<br />
3		0		NULL<br />
4		0		NULL<br />
5		2		1<br />
6		2		2<br />
7		2		3<br />
8		3		1<br />
9		2		NULL</p>
<p>We can see that only the field <em>idnode_parent</em> updated as expected, the <em>position</em> field for the moved nodes being set to NULL.</p>
<p>b) We reset the table to the initial test data and we run the above query with the difference of using the ELSE clause in the CASE expression:</p>
<pre class="code brush:sql">UPDATE node
SET idnode_parent = CASE(idnode_parent)
WHEN 1 THEN 0
WHEN 7 THEN 2
ELSE idnode_parent
END,
position = CASE(idnode_parent)
WHEN 1 THEN 1
WHEN 7 THEN 3
ELSE position
END
WHERE idnode_parent IN (1, 7);</pre>
<p>The result is:</p>
<p>idnode	idnode_parent	position<br />
1		0		1<br />
2		0		2<br />
3		0		1<br />
4		0		2<br />
5		2		1<br />
6		2		2<br />
7		2		3<br />
8		3		1<br />
9		2		1</p>
<p>So the <em>idnode_parent</em> field updates correctly, but <em>position</em> remains unchanged.</p>
<p>My conclusion is that that the query runs as if there were two different queries running over the bunch of rows resulted after evaluating the WHERE condition, the second CASE operator applying over the data modified by the first CASE operator:<br />
1. WHERE condition is evaluated; resulted data set:</p>
<p>idnode	idnode_parent	position<br />
3		1		1<br />
4		1		2<br />
9		7		1</p>
<p>2. <em>idnode_parent</em> is set by evaluating the first CASE expression:</p>
<p>idnode	idnode_parent	position<br />
3		0		1<br />
4		0		2<br />
9		2		1<br />
3. <em>position</em> is set by evaluating the second CASE expression:</p>
<p>a) Using the query without the ELSE condition, <em>position</em> is set to NULL for all the rows in the data set, as after running the first CASE expression there are no more rows with the <em>idnode_parent</em> needed for the second CASE expression:<br />
idnode	idnode_parent	position<br />
3		0		NULL<br />
4		0		NULL<br />
9		2		NULL</p>
<p>b) Using the query with the ELSE condition, <em>position</em> remains unchanged for all the rows in the data set, as there are no more rows with the needed <em>idnode_parent</em>, as they were modified by applying the previous CASE operator, and the ELSE condition is evaluated:<br />
idnode	idnode_parent	position<br />
3		0		1<br />
4		0		2<br />
9		2		1</p>
<p>So if we want the query to run correctly, we set the position first, and then the id of the parent node, as <em>position</em> does not modify data needed for subsequent <em>idnode_parent</em> updates in the same query:</p>
<pre class="code brush:sql">UPDATE node
SET position = CASE(idnode_parent)
WHEN 1 THEN 1
WHEN 7 THEN 3
END,
idnode_parent = CASE(idnode_parent)
WHEN 1 THEN 0
WHEN 7 THEN 2
END
WHERE idnode_parent IN (1, 7);</pre>
<p>We finally obtain the expected result:<br />
idnode	idnode_parent	position<br />
3		0		1<br />
4		0		1<br />
9		2		3</p>
]]></content:encoded>
			<wfw:commentRss>http://www.theerrormessage.com/2010/07/updating-multiple-fields-in-multiple-rows-with-different-values-in-a-single-query-in-mysql-using-the-case-operator-does-not-supply-a-correct-result/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NTLDR is missing</title>
		<link>http://www.theerrormessage.com/2010/04/ntldr-is-missing/</link>
		<comments>http://www.theerrormessage.com/2010/04/ntldr-is-missing/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 22:07:57 +0000</pubDate>
		<dc:creator>thalissar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.theerrormessage.com/?p=189</guid>
		<description><![CDATA[Problem: Computer with Windows XP Professional operation system froze unexpectedly. No recent hardware changes performed, no applications recently installed. I reeboted. &#8220;NTLDR is missing&#8221; error occured. I noticed that the system did not detect the hard disk drive where the operating system resided but I fixed this by reseating the IDE cables. Though the error [...]]]></description>
			<content:encoded><![CDATA[<p>Problem: Computer with Windows XP Professional operation system froze unexpectedly. No recent hardware changes performed, no applications recently installed. I reeboted. &#8220;NTLDR is missing&#8221; error occured.</p>
<p>I noticed that the system did not detect the hard disk drive where the operating system resided but I fixed this by reseating the IDE cables. Though the error persisted.</p>
<p>I then inserted the Windows XP boot CD in the CD-ROM drive in order to repair the operaton system. But I realized that if I changed in BIOS the Primary Boot Device from Hard Disk to CD-ROM, when the system asked if I wanted to boot from CD, I should <strong>not</strong> press any key and the system booted from Hard Disk. But this only happend if a bootable Windows XP CD was in the CD-ROM Drive.</p>
<p>While searching the Internet for solutions to this problem, i found <a href="http://tinyempire.com/notes/ntldrismissing.htm#What_if_the_bootdisk_worked,_but_I_can%27t_get_into_Windows_without_it?" target="_blank">this article</a>.<br />
No need for me to make a bootable anything as this guy describes here, but something caught my eye:</p>
<p><em>Once back into Windows, right click on the My Computer option, choose the Manage option. The Computer Management window will open, click on &#8220;Disk Management&#8221; on the left pane. One of the disks it lists, and one of the drives on it, will need to be marked as active. It will be which drive letter you have placed the 3 boot files into (this will likely be the C: drive on Disk 0). Right click on that drive letter and select &#8220;Mark Partition as Active&#8221;, you may first have to convert the partition to a Primary partition before you can mark it as active. Close and reboot.</em></p>
<p>I noticed that in Disk Management it was marked as active a partition on a slave hard disk. I wanted to unmark it, but I realized that I could not do that from the Disk Management interface.<br />
Reading on the mentioned article, I found the solution to this last occured problem:<br />
<a href="http://tinyempire.com/notes/ntldr/markingpartitionactive.htm" target="_blank">Mark Partition as Active with diskpart from Jim the Bean</a></p>
<p>I did that and it worked. It not only solved the active partition problem, but also my bigger problem as the system reebooted just fine with the Primary Boot Device set to Hard Disk and there was no need to set any partition as active on my system.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.theerrormessage.com/2010/04/ntldr-is-missing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to convert server date and time to the local date and time taking into account daylight saving time</title>
		<link>http://www.theerrormessage.com/2009/10/convert-server-time-to-local-time-taking-into-account-daylight-saving-time/</link>
		<comments>http://www.theerrormessage.com/2009/10/convert-server-time-to-local-time-taking-into-account-daylight-saving-time/#comments</comments>
		<pubDate>Sat, 31 Oct 2009 20:04:12 +0000</pubDate>
		<dc:creator>thalissar</dc:creator>
				<category><![CDATA[How to]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.theerrormessage.com/?p=39</guid>
		<description><![CDATA[&#8216;Many countries, or even parts of countries, adopt daylight saving time (DST, also known as &#8220;Summer Time&#8221;) during part of the year. This typically involves advancing clocks by an hour near the start of spring and adjusting back in autumn (&#8220;spring&#8221; forward, &#8220;fall&#8221; back).&#8217; (see Wikipedia) Now I will demonstrate how we can convert a [...]]]></description>
			<content:encoded><![CDATA[<p>&#8216;Many countries, or even parts of countries, adopt daylight saving time (DST, also known as &#8220;Summer Time&#8221;) during part of the year. This typically involves advancing clocks by an hour near the start of spring and adjusting back in autumn (&#8220;spring&#8221; forward, &#8220;fall&#8221; back).&#8217; (see <a title="Time zone, Daylight saving time" href="http://en.wikipedia.org/wiki/Time_zone#Daylight_saving_time" target="_blank">Wikipedia</a>)</p>
<p>Now I will demonstrate how we can convert a server date and time to the corresponding date and time in another timezone in Europe, taking Romania as example.</p>
<p>&#8216;All countries in Europe except Iceland observe DST, and most change on the same date and time, starting on the last Sunday in March and ending on the last Sunday in October.&#8217;<br />
&#8216;In the West European (UTC), Central European (CET, UTC+1), and East European (UTC+2) time zones the change is simultaneous: on both dates the clocks are changed everywhere at 01:00 UTC, i.e. from local times of 01:00/02:00/03:00 to 02:00/03:00/04:00 in March, and vice versa in October.&#8217; (see <a title="Time zone, Daylight saving time in Europe" href="http://en.wikipedia.org/wiki/Daylight_saving_time_around_the_world#In_general" target="_blank">Wikipedia</a>)</p>
<p>Romania is a country in the Eastern Europe, which falls under the East European Time (EET) also known as UTC+2 time zone and uses Eastern European Summer Time (UTC+3) as a summer daylight saving time.</p>
<p>The next function will be used to find out the offset in hours from UTC (GMT) of a local date and time of Romania or another region that switches between DST and standard time on the same date and time as Romania (is the local date and time in DST or in standard time?)</p>
<pre class="code brush:php">function local_offset_from_utc($timestamp, $standard_offset)
//$timestamp - the timestamp of the server date and time we want to convert to local date and time
//$standard_offset - the offset from UTC of the local date and time when observing the standard time; in daylight saving time the offset is $standard_offset + 1
{
	$year = gmdate("Y", $timestamp); //get the UTC year of the given date and time
//get the date to 'spring forward'
	$mar_31_utc_ts = gmmktime(0, 0, 0, 4, 0, $year); //the UTC timestamp of March 31, the last day of March, equivalent to gmmktime(0, 0, 0, 3, 31, $year)
	$last_sun_mar = 31 - gmdate("w", $mar_31_utc_ts); //the day of the month under which falls the last Sunday in March
	$spring_ts = gmmktime(1, 0, 0, 3, $last_sun_mar, $year); //the timestamp of the last Sunday in March 01:00 UTC
//get the date to 'fall back'
	$oct_31_utc_ts = gmmktime(0, 0, 0, 11, 0, $year); //the UTC timestamp of October 31, the last day of October, equivalent to gmmktime(0, 0, 0, 10, 31, $year)
	$last_sun_oct = 31 - gmdate("w", $oct_31_utc_ts); //the day of the month under which falls the last Sunday in October
	$fall_ts = gmmktime(1, 0, 0, 10, $last_sun_oct, $year); //the timestamp of the last Sunday in October, 01:00 UTC
	if($timestamp >= $spring_ts &#038;&#038; $timestamp < $fall_ts) //daylight saving time
	{
		return $standard_offset + 1;
	}
//standard time
	return $standard_offset;
}</pre>
<p>If the server switches between DST and standard time simultaneously with your timezone, you can simply use date("I") to find out if your local date and time is in daylight saving time or standard time:</p>
<pre class="code brush:php">if(date("I", $timestamp) == 1)
{
	$offset = $standard_offset + 1;
}
else
{
	$offset = $standard_offset;
}</pre>
<p>Be careful with that, because a sever don't always switch between DST and standard time at the same hour as the timezone it has set, for example my server switches from DST to standard time at 03:00 UTC+3, which becomes 02:00 UTC+2, when it should go from 04:00 UTC+3 to 03:00 UTC+2). So I better use the function above that works not caring if or when the timezone of the server switches between DST and standard time.</p>
<p>If an offset of a timezone from UTC is negative, then the UTC date and time is greater than the corresponding date and time in the considered timezone; if the offset is positive then the UTC date and time is lower than the corresponding date and time in the considered timezone. If we consider <em>t</em> being the date and time in a given timezone, <em>utc</em> being the corresponding UTC date and time and <em>offset</em> being the offset of the given timezone from UTC, then we have:</p>
<p><em>t = utc + offset<br />
utc = t - offset</em></p>
<p>So if we consider <em>t1</em> being a server date and time and <em>o1</em> being the offset of the timezone of the server from UTC (in hours) and <em>t2</em> being the local date and time and <em>o2</em> being the offset of the timezone of the server from UTC (in hours) we have:</p>
<p><em>utc = t1 - o1<br />
t2 = utc + o2 = t1 - o1 + o2</em></p>
<p>In practice we only have a server date and time which we convert to timestamp <em>ts1</em> based on which we find out the timestamp <em>ts2</em> when the date and time in the timezone of the server equaled/will equal to the local date and time corresponding to <em>ts1</em>:</p>
<p><em>ts2 = ts1 - os1 + os2</em>, where <em>os1 = o1 * 60 *60</em> seconds and <em>os2 = o2 * 60 *60</em> seconds</p>
<p>E.g. Let's consider the timezone of the server date and time is UTC-5 and Romania is in standard time (has an offset of 2 hours from UTC).</p>
<p>The UTC date and time that corresponds to the given timestamp equals to the server date and time that was/will be 5 hours later than the given timestamp:</p>
<p><em>ts_aux = ts1 - (-5 * 3600) = ts1 + 5 * 3600</em></p>
<p>The local date and time of Romania corresponding to the given timestamp equals to the UTC date and time that was/will be 2 hours later than the UTC date and time computed above:</p>
<p><em>ts2 = ts_aux + 2 * 3600 = ts1 + (5 + 2) * 3600 = ts1 + 7 * 3600</em></p>
<p>But this is NOT true if the server time and date that equals the needed local date and time falls under DST and the original server date falls under standard time or vice versa, which means that the offsets from UTC of the two server dates are different by 1 hour.</p>
<p>For example, if the server we considered before is in UTC-5 DST and goes back one hour on the first of November at 03:00:00 local server time and we want to see what Romania local date and time corresponds to the server date and time November 1st 01:00:00, then, applying the formula above, we will obtain a timstamp that corresponds to the server date and time November 1st 07:00:00 which should correspond to the local Romania time for the original server time, but the correct Romania date and time being November 1st 08:00:00. That is because, between November 1st 01:00:00 and November 1st 07:00:00, the server goes back one hour so that 03:00:00 DST becomes 02:00:00 standard time and 08:00:00 becomes 07:00:00, while the Romania time does not, Romania switching to DST one week earlier, so the correct formula in this case is:</p>
<p><em>ts2 = ts1 - os1 + os2 + 3600<br />
ts2 = ts1 + (5 + 2 + 1) * 3600 = ts1 + 8 * 3600</em></p>
<p>Similarly, if the server switches from standard time to DST between the two dates, the formula becomes:</p>
<p><em>ts2 = ts1 - os1 + os2 - 3600<br />
ts2 = ts1 + (5 + 2 - 1) * 3600 = ts1 + 6 * 3600</em></p>
<p>The next function is used to determine what the timestamp was/will be in the timezone of the server when the server date and time equaled/will be equal to the needed local date and time.</p>
<pre class="code brush:php">function get_timestamp_for_local($date = "", $standard_offset = 2)
{
	if(!empty($date))
	{
		$timestamp = strtotime($date);
	}
	else
	{
		$timestamp = time();
	}
	$os1 = date("Z", $timestamp);
	$os2 = local_offset_from_utc($timestamp, $standard_offset) * 3600;
	$ts = $timestamp - $os1 + $os2;
	//check the offset from UTC of the server date and time that equal the needed local date and time
	$os3 = date("Z", $ts);
	if($os3 == $os1) //the two server dates are both in DST or both in standard time
	{
		return $ts;
	}
	elseif($os3 > $os1) //the server date and time that equal the needed local date and time are in DST and the original server date and time are in standard time
	{
		return $ts - 3600;
	}
 	//the server date and time that equal the needed local date and time are in standard time and the original server date and time are in DST
	return $ts + 3600;
}</pre>
<p>And finally we get the needed date and time:</p>
<pre class="code brush:php">function get_ro_date($date)
{
	return date("d.m.Y H:i:s", get_timestamp_for_local($date));
}</pre>
<p>Next l will show how we can convert a server date and time to the corresponding date and time in another timezone in North America, taking the State of Washington as example.</p>
<p>'North America generally follows the same procedure, with each time zone switching at 02:00 LST (local standard time) to 03:00 LDT (local daylight time) on the second Sunday in March, and back from 02:00 LDT to 01:00 LST on the first Sunday in November since 2007.'<br />
In the United States of America, 'the start of DST now occurs on the second Sunday in March and ends on the first Sunday in November.' (see <a title="Daylight saving time in North America" href="http://en.wikipedia.org/wiki/Daylight_saving_time_around_the_world#North_America" target="_blank">Wikipedia</a>)</p>
<p>The State of Washington falls under the Pacific Time Zone (PT), which is Pacific Standard Time (PST) or UTC-8 when observing standard time and Pacific Daylight Time (PDT) or UTC-7 during daylight saving time.</p>
<p>So we have to change the previous <em>local_offset_from_utc</em> function to find out the offset in hours from UTC (GMT) of a local date and time of Washington:</p>
<pre class="code brush:php">function local_offset_from_utc2($timestamp, $standard_offset, $spring_forward_hour, $fall_back_hour)
//$timestamp - the timestamp of the server date and time we want to convert to local date and time
//$standard_offset - the offset from UTC of the local date and time when observing the standard time; in daylight saving time the offset is $standard_offset + 1
//$spring_forward_hour - the hour of the local time when switching to DST
//$fall_back_hour - the hour of the local time when switching to standard time
{
//find out the year of the local date and time corresponding to the given server date and time, based on the corresponding UTC date and time
	$year = gmdate("Y", $timestamp); //UTC year of the given server date and time
	if($standard_offset &lt; 0) //local timezone is behind UTC
	{
		//if the given sever date and time corresponds to January the 1st in UTC and the UTC hour is lower than the absolute value of the offset of the local time from UTC, then the corresponding local date and time falls in the year previous to the UTC year
		$month = gmdate("n", $timestamp);
		if($month == 1)
		{
			$day = gmdate("j", $timestamp);
			if($day == 1)
			{
				$hour = gmdate("G", $timestamp);
				if($hour + $standard_offset &lt; 0)
				{
					$year -= 1;
				}
			}
		}
	}
	else //local timezone time is ahead of UTC
	{
		//if the given sever date and time corresponds to December 31 in UTC and the sum of UTC hour and the offset of the local time from UTC is greater than 24, then the corresponding local date and time falls in the year subsequent to the UTC year
		$month = gmdate("n", $timestamp);
		if($month == 12)
		{
			$day = gmdate("j", $timestamp);
			if($day == 31)
			{
				$hour = gmdate("G", $timestamp);
				if($hour + $standard_offset &gt; 24)
				{
					$year += 1;
				}
			}
		}
	}
	//get the date to 'spring forward'
	$mar_1_utc_ts = gmmktime(0, 0, 0, 3, 1, $year); //the timestamp for the UTC time of March the 1st, 00:00:00
	$mar_1_day_of_week = gmdate("w", $mar_1_utc_ts);
	//compute the day of the month under which falls the second Sunday in March
	if($mar_1_day_of_week &gt; 0) //the day of the week of the 1st of March is not Sunday
	{
		$second_sun_mar = 15 - $mar_1_day_of_week;
	}
	else
	{
		$second_sun_mar = 8;
	}
	$spring_local_ts = gmmktime($spring_forward_hour - $standard_offset, 0, 0, 3, $second_sun_mar, $year);
	//get the date to 'fall back'
	$nov_1_utc_ts = gmmktime(0, 0, 0, 11, 1, $year); //the timestamp for the UTC time of November the 1st, 00:00:00
	$nov_1_day_of_week = gmdate("w", $nov_1_utc_ts);
//compute the day of the month under which falls the first Sunday in November
	if($nov_1_day_of_week &gt; 0) //the day of the week of the 1st of November is not Sunday
	{
		$first_sun_nov = 8 - $nov_1_day_of_week;
	}
	else
	{
		$first_sun_nov = 1;
	}
	$fall_local_ts = gmmktime($fall_back_hour - ($standard_offset + 1), 0, 0, 11, $first_sun_nov, $year);
	if($timestamp &gt;= $spring_local_ts &amp;&amp; $timestamp &lt; $fall_local_ts) //daylight saving time
	{
		return $standard_offset + 1;
	}
	//standard time
	return $standard_offset;
}
</pre>
<p>The function <em>get_timestamp_for_local</em> remains the same, only we add 2 more paramters to it which will be needed when calling  the <em></em> function:</p>
<pre class="code brush:php">function get_timestamp_for_local2($date = "", $standard_offset = -8, $spring_forward_hour = 2, $fall_back_hour = 3)
{
	if(!empty($date))
	{
		$timestamp = strtotime($date);
	}
	else
	{
		$timestamp = time();
	}
	$os1 = date("Z", $timestamp);
	$os2 = local_offset_from_utc2($timestamp, $standard_offset, $spring_forward_hour, $fall_back_hour) * 3600;
	$ts = $timestamp - $os1 + $os2;
	//check the offset from UTC of the server date and time that equal the needed local date and time
	$os3 = date("Z", $ts);
	if($os3 == $os1) //the two dates are both in DST or both in standard time
	{
		return $ts;
	}
	elseif($os3 > $os1) //the server date and time that equal the needed local date and time are in DST and the original server date and time are in standard time
	{
		return $ts - 3600;
	}
	//the server date and time that equal the needed local date and time are in standard time and the original server date and time are in DST
	return $ts + 3600;
}</pre>
<p>And now we can find out the date and time in the State of Washington that corresponds to the given server date and time:</p>
<pre class="code brush:php">function get_wa_date($date)
{
	return date("Y-m-d H:i:s", get_timestamp_for_local2($date));
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.theerrormessage.com/2009/10/convert-server-time-to-local-time-taking-into-account-daylight-saving-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SoftException in Application.cpp:544: Directory &#8220;/path/dir&#8221; is writeable by group</title>
		<link>http://www.theerrormessage.com/2009/10/softexception-in-application-cpp544-directory-pathdir-is-writeable-by-group/</link>
		<comments>http://www.theerrormessage.com/2009/10/softexception-in-application-cpp544-directory-pathdir-is-writeable-by-group/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 16:14:53 +0000</pubDate>
		<dc:creator>gbl</dc:creator>
				<category><![CDATA[Apache Web Server]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.theerrormessage.com/?p=25</guid>
		<description><![CDATA[Full error message: SoftException in Application.cpp:544: Directory &#8220;/path/to/directory&#8221; is writeable by group The error apeared in cpanel logs at a hosting company and was related to a directory I created via ftp and where I tried to run some php script. When accessing the script from the web browser i got the error &#8220;500 Internal [...]]]></description>
			<content:encoded><![CDATA[<p>Full error message: <em>SoftException in Application.cpp:544: Directory &#8220;/path/to/directory&#8221; is writeable by group</em></p>
<p>The error apeared in cpanel logs at a hosting company and was related to a directory I created via ftp and where I tried to run some php script. When accessing the script from the web browser i got the error &#8220;500 Internal Server Error&#8221;</p>
<p>The problem is that Apache 2.0 server doesn&#8217;t allow in some cases (i don&#8217;t know these cases yet) that the directories created with write access rights set to all unless it&#8217;s set by the same unix user as the user running apache process. In order to fix this we need to create the folder from the same user as apache user. To do this we need to create the folder or to change the access rights from php.</p>
<p>The fix is to upload a small php file with the following code:</p>
<pre class="code brush:php">&lt;?php
chmod("./dir", 0755);
?&gt;</pre>
<p>After we set the access right on &#8220;dir&#8221; to 777 we run the  php script then the error should not appear anymore.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.theerrormessage.com/2009/10/softexception-in-application-cpp544-directory-pathdir-is-writeable-by-group/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to recover a hard deleted store folder in Microsoft Outlook Express 6</title>
		<link>http://www.theerrormessage.com/2009/09/how-to-recover-a-hard-deleted-store-folder-in-microsoft-outlook/</link>
		<comments>http://www.theerrormessage.com/2009/09/how-to-recover-a-hard-deleted-store-folder-in-microsoft-outlook/#comments</comments>
		<pubDate>Sun, 13 Sep 2009 15:49:22 +0000</pubDate>
		<dc:creator>thalissar</dc:creator>
				<category><![CDATA[How to]]></category>

		<guid isPermaLink="false">http://www.theerrormessage.com/2009/09/13/how-to-recover-a-hard-deleted-store-folder-in-microsoft-outlook/</guid>
		<description><![CDATA[It happened for several times that I accidentally hard deleted a store folder in Microsoft Outlook Express 6 when trying to delete an email in that folder (both the folder and the e-mail looked like being selected, but it seems that the focus was on the folder and not the e-mail as I expected). Seems [...]]]></description>
			<content:encoded><![CDATA[<p>It happened for several times that I accidentally hard deleted a store folder in Microsoft Outlook Express 6 when trying to delete an email in that folder (both the folder and the e-mail looked like being selected, but it seems that the focus was on the folder and not the e-mail as I expected).</p>
<p>Seems that when we access (select) for the first time a store folder, say &#8220;MyFolder&#8221;, we created in Outlook Express, a .dbx file is automatically created in the Outlook Express Mail directory &#8220;C:\Documents and Settings\&lt;username&gt;\Local Settings\Application Data\Identities\{&lt;identity-code&gt;}\Microsoft\Outlook Express&#8221;.<br />
If it doesn&#8217;t already exist a file named MyFolder.dbx in the OE Mail directory, such a file is created and a refernce from the store folder &#8220;MyFolder&#8221; to this .dbx file is created in the Folder.dbx file in the OE Mail directory.<br />
If there already is a .dbx file in The OE Mail directory with the same name as the folder we created (MyFolder.dbx), then, when we access the folder &#8220;MyFolder&#8221;, it will be created a .dbx file named MyFolder(1).dbx, if does not already exist a file named MyFolder(1).dbx in the OE Mail directory, otherwise a file named MyFolder(2).dbx will be created etc. Also a reference from &#8220;MyFolder&#8221; to the newly created .dbx file is created in the Folders.dbx file.</p>
<p>To see which .dbx file is associated with a certain store folder in Outlook Express, right click on that folder and select Properties; under the General tab you&#8217;ll find the full path to the .dbx file the folder is stored in.</p>
<p>When we delete a store folder in Outlook Express, only the reference to the .dbx file is deleted, the .dbx file remaining orphan. So, if we want to recover the deleted folder, a new folder and a reference between it and the orphaned .dbx file should be created. This is how you do that:</p>
<p>1. Move, not copy, the orphaned .dbx file from OE Mail directory to another location.<br />
Do not just copy the file elsewhere because if there already is a .dbx file with the same name as the folder you create, say MyFolder.dbx, then when you select the newly created folder it will be created a .dbx file named like MyFolder(1).dbx as explained before.</p>
<p>2. In Outlook Express, create a folder with exactlty the same name (case sensitive) as the orphaned .dbx file, select the newly created folder so that a new .dbx file is automatically created (this should have the same name as the orphaned .dbx file), close OE.</p>
<p>3. Overwrite the new (empty) .dbx file in your OE Mail directory with the orphaned file and open OE.</p>
<p>4. If you had any mail message rules involving the deleted folder, repair them, because OE deletes the references to the folder from the message rules once you delete a folder, but it does not remake them once you remake the folder (go to Tools -> Messages rules -> Mail).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.theerrormessage.com/2009/09/how-to-recover-a-hard-deleted-store-folder-in-microsoft-outlook/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

