Problem with Convert and Danish
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Problem with Convert and Danish
Hi All…
I am parsing XMLfiles from a device, and the Danish version of this device formats "March 5, 2012" as "Marts 5, 2012". Problem is, LC's convert command does not recognize this as a valid date even on systems set to Danish date formatting. I have tried setting the useSystemDate just before converting without success.
Both HyperCard and SuperCard handle this without issue. How can I get LiveCode to handle this correctly?
Thanks.
I am parsing XMLfiles from a device, and the Danish version of this device formats "March 5, 2012" as "Marts 5, 2012". Problem is, LC's convert command does not recognize this as a valid date even on systems set to Danish date formatting. I have tried setting the useSystemDate just before converting without success.
Both HyperCard and SuperCard handle this without issue. How can I get LiveCode to handle this correctly?
Thanks.
Re: Problem with Convert and Danish
Hi,
what did you script so far?
Did you use the form "convert xxx FROM zzz to yyy"?
Best
Klaus
what did you script so far?
Did you use the form "convert xxx FROM zzz to yyy"?
Best
Klaus
Re: Problem with Convert and Danish
Hi Klaus,
Code: Select all
set the usesystemdate to true
-- answer the usesystemdate
get fld "date"
convert it from long date to dateitems --also tried just 'convert it to dateitems'
put it into fld "dateitems"
put the monthnames --odd that this actually puts the correct Danish month names
Re: Problem with Convert and Danish
Hi,
please re-read the part about "convert" in the docs
You need to tell LiveCode what the SOURCE format is, as I showed in my first reply!
I you don't then LC will think the SOURCE format is an ENGLISH date!
Try this:
...
get fld "date"
## !!!
convert it from long SYSTEM date to dateitems
## !!!
put it into fld "dateitems"
...
Best
Klaus
please re-read the part about "convert" in the docs

You need to tell LiveCode what the SOURCE format is, as I showed in my first reply!
I you don't then LC will think the SOURCE format is an ENGLISH date!
Try this:
...
get fld "date"
## !!!
convert it from long SYSTEM date to dateitems
## !!!
put it into fld "dateitems"
...
Best
Klaus
Re: Problem with Convert and Danish
Thanks Klaus… but I am afraid it still returns "marts 5, 2012"
BTW… the docs say
"You can optionally use the english or system keyword before the short, abbreviated, or long date or time. If the useSystemDate is true, or if you use the system keyword, the user's current system preferences are used to format the date or time. Otherwise, the standard US date and time formats are used."
So I took this to mean setting the usesystemdate was enough.
Code: Select all
set the usesystemdate to true
get "marts 5, 2012"
convert it from long system date to dateitems
answer it
"You can optionally use the english or system keyword before the short, abbreviated, or long date or time. If the useSystemDate is true, or if you use the system keyword, the user's current system preferences are used to format the date or time. Otherwise, the standard US date and time formats are used."
So I took this to mean setting the usesystemdate was enough.
Re: Problem with Convert and Danish
Oh, sorry, overlooked that one, sure that should be enough for "convert".
But I am afraid this is no a convertible date format at all!?
"the long system date" and "the abbr system date" ALWAYS show the weekdayname here, which is missing in your example,
so "convert" obviously cannot convert from this "unkown" format to anything else!
Abbreviated system date: Mon, Jul 2, 2012
Long system date: Montag, 2. Juli 2012
What do you get with:"the long system date" and "the abbr system date"?
I bet the leading week day name, right?
Then you are out of luck
Best
Klaus
But I am afraid this is no a convertible date format at all!?
"the long system date" and "the abbr system date" ALWAYS show the weekdayname here, which is missing in your example,
so "convert" obviously cannot convert from this "unkown" format to anything else!
Abbreviated system date: Mon, Jul 2, 2012
Long system date: Montag, 2. Juli 2012
What do you get with:"the long system date" and "the abbr system date"?
I bet the leading week day name, right?
Then you are out of luck

Best
Klaus
Re: Problem with Convert and Danish
"The long system date" returns "mandag 2. juli 2012".
"The abbr system date" returns "man 2. jul. 2012".
But if it is aware of the proper month names (the monthNames), why does it not see "marts" as "March" in the same way that HyperCard and SuperCard do?
Oh well… I'll chalk this one up to just another one of LC's inexplicable behaviors. I suppose I can add a routine to walk the list of monthNames to determine just what month it is.
Thanks!
"The abbr system date" returns "man 2. jul. 2012".
But if it is aware of the proper month names (the monthNames), why does it not see "marts" as "March" in the same way that HyperCard and SuperCard do?
Oh well… I'll chalk this one up to just another one of LC's inexplicable behaviors. I suppose I can add a routine to walk the list of monthNames to determine just what month it is.
Thanks!
Re: Problem with Convert and Danish
Well, get used to it and don't shoot the messenger, thanks 

Re: Problem with Convert and Danish
Here's my little fix:
Code: Select all
function americanize thedate
set the useSystemDate to true
put the monthnames into theMonths
put word 1 of the date into theMonth
get lineoffset(theMonth,theMonths)
switch it
case 1
replace themonth with "January" in thedate
break
case 2
replace themonth with "February" in thedate
break
case 3
replace themonth with "March" in thedate
break
case 4
replace themonth with "April" in thedate
break
case 5
replace themonth with "May" in thedate
break
case 6
replace themonth with "June" in thedate
break
case 7
replace themonth with "July" in thedate
break
case 8
replace themonth with "August" in thedate
break
case 9
replace themonth with "September" in thedate
break
case 10
replace themonth with "October" in thedate
break
case 11
replace themonth with "November" in thedate
break
case 12
replace themonth with "December" in thedate
break
default
end switch
return theDate
end americanize
Re: Problem with Convert and Danish
Hi,
fine, but you can make it a tad shorter:
Best
Klaus
fine, but you can make it a tad shorter:
Code: Select all
function americanize thedate
set the useSystemDate to true
put the monthnames into theMonths
put word 1 of the date into theMonth
put lineoffset(theMonth,theMonths) into tTargetLine
## Now get the list of ENGLISH monthnames:
set the useSystemDate to FALSE
put the monthnames into theEnglishMonths
## We already have the list of english monthnames, we only need to get the correct line:
put line tTargetLine of tEnglishMonths into tTargetMonth
## Now replace
replace themonth with tTargetMonth in thedate
return theDate
end americanize

Best
Klaus
Re: Problem with Convert and Danish
Nice. But you did not account for lineOffset returning 0.
Re: Problem with Convert and Danish
You are correct!
Best
Klaus

Code: Select all
function americanize thedate
set the useSystemDate to true
put the monthnames into theMonths
put word 1 of the date into theMonth
put lineoffset(theMonth,theMonths) into tTargetLine
## Here we are :-)
if tTargetLine = 0 then
return thedate
end if
## Now get the list of ENGLISH monthnames:
set the useSystemDate to FALSE
put the monthnames into theEnglishMonths
## We already have the list of english monthnames, we only need to get the correct line:
put line tTargetLine of tEnglishMonths into tTargetMonth
## Now replace
replace themonth with tTargetMonth in thedate
return theDate
end americanize
Klaus