Based on Translation Bot, I created another multi-step function for our Sametime bot. It shows current exchange rates between different currencies (from Yahoo Finance).
You can try it here:
Currency Exchange Sametime bot
Instructions:
1) Type 1 and click "Say" button (or press Enter key).
2) Type 2 to set Euro as source currency and press Enter key.
3) Type 7 to set Swedish crown as target currency and press Enter key.
The result is the current exchange rate according to Yahoo finance.
Tags: sametime sametime bot
Thursday, August 21, 2008
Sunday, August 17, 2008
Another Javascript feature
Javascript uses pointers when assigning objects. This can lead to unexpected results for those who are used to work with LotusScript and Visual Basic, where data is copied to the new object and is no longer connected to the original object.
In the example below note that date2 object was not deliberately changed after it was initially set, but still at the end of the script it gets a new value which is the same as the changed date1 object.
<script>
var date1=new Date();
var date2=date1;
alert(date2); //shows Sun Aug 17 11:46:50 UTC+0200 2008
date1.setMonth(5);
date1.setDate(9);
alert(date2); //shows Mon Jun 9 11:46:50 UTC+0200 2008
</script>
run example
It also works in the opposite direction: if you change date2, the date1 will also be changed.
In the example below note that date2 object was not deliberately changed after it was initially set, but still at the end of the script it gets a new value which is the same as the changed date1 object.
<script>
var date1=new Date();
var date2=date1;
alert(date2); //shows Sun Aug 17 11:46:50 UTC+0200 2008
date1.setMonth(5);
date1.setDate(9);
alert(date2); //shows Mon Jun 9 11:46:50 UTC+0200 2008
</script>
run example
It also works in the opposite direction: if you change date2, the date1 will also be changed.
Monday, August 04, 2008
Why javascript doesn't like August and September in date validation
Do you like August and September months? Well, then bad news, because JavaScript doesn't like them. Using parseInt function without base parameter to convert from text to number when validating month number 08 gives 0.
This is true only for August(month "08") and September(month "09"), so it can take a while until the error is discovered. Why is that happening? Well, probably because genious developers of Javascript API thought that people use octal (base8) as default. Numbers until 08(August, put as "08" in dates) are converted correctly because they are same in octal as in base10, and numbers after 09 are recognized correctly because they(almost never) have a non-zero leading number. In between we have our poor "08" and "09".
Fortunately, there is a parameter you can add to parseInt function which specifies the base, e.g. parseInt("09", 10). But was it really so smart to use base8 as default for numbers beginning with 0 instead of always using base10 and requiring user to explicitely enter parameter for other (less used) bases?
Alternatives for parseInt are parseFloat and Number functions:
Doesn't work correctly:
javascript:alert(parseInt("09"))
Works correctly:
javascript:alert(parseInt("09", 10))
javascript:alert(Number("09"))
javascript:alert(parseFloat("09"))
This is true only for August(month "08") and September(month "09"), so it can take a while until the error is discovered. Why is that happening? Well, probably because genious developers of Javascript API thought that people use octal (base8) as default. Numbers until 08(August, put as "08" in dates) are converted correctly because they are same in octal as in base10, and numbers after 09 are recognized correctly because they(almost never) have a non-zero leading number. In between we have our poor "08" and "09".
Fortunately, there is a parameter you can add to parseInt function which specifies the base, e.g. parseInt("09", 10). But was it really so smart to use base8 as default for numbers beginning with 0 instead of always using base10 and requiring user to explicitely enter parameter for other (less used) bases?
Alternatives for parseInt are parseFloat and Number functions:
Doesn't work correctly:
javascript:alert(parseInt("09"))
Works correctly:
javascript:alert(parseInt("09", 10))
javascript:alert(Number("09"))
javascript:alert(parseFloat("09"))
Subscribe to:
Posts (Atom)