Tuesday, May 27, 2003

Time in Domino RSS Feeds

I have just spent some fun time fiddling to get the correct date formats in my new RSS feed.

The initial RSS feed date code in FreeDomblog does not validate, but I found that Johan has some code that works (almost). Here it is:

t:=@Created;
y:=@Right("00" + @Text(@Year(t)); 4);
m:=@Right("0" + @Text(@Month(t)); 2);
d:=@Right("0" + @Text(@Day(t)); 2);
s1:="-";
s2:=":";
h:=@Right("0" + @Text(@Hour(t)); 2);
mm:=@Right("0" + @Text(@Minute(t)); 2);
s:=@Right("0" + @Text(@Second(t)); 2);
zone:=@Integer(0-@Zone(t));
z:=@If(zone > 0; "+"; zone < 0; "-"; "Z") + @If(zone=0; ""; @Right("0" + @Text(zone); 2) + ":00");

RSSDate := y + s1 + m + s1 + d + "T" + h + s2 + mm + s2 + s + z;

It works OK for Timezones east of GMT (ie europe, asia etc, but not for TZ west). I have a server in TZ -8 and it returns:
2003-05-25T18:11:44--8:00

This is because in the evaluation of @text(zone) returns "-8" for western zones because zone is a signed integer.

@abs (Absolute Value) will remove the sign from the integer and solve the problem.

If you replace the formula for z with this:

z:=@If(zone > 0; "+"; zone < 0; "-"; "Z") + @If(zone=0; ""; @Right("0" + @Text(@abs(zone)); 2) + ":00");

then all is well.

No comments: