Official Soldat Forums

Server Talk => Scripting Discussions and Help => Topic started by: freestyler on June 06, 2009, 04:22:24 pm

Title: [solved] Day of week
Post by: freestyler on June 06, 2009, 04:22:24 pm
I am finishing a new script but I can't get it to work on non-English platforms. I want to get the number of day of week (Monday = 1, Tuesday = 2, ..., Sunday = 7); as for now, I have the following:
Code: [Select]
function dayofweek(day: string): byte;
  begin
    result := 0;
    case day of
      'Mon': result := 1;
      'Tue': result := 2;
      'Wed': result := 3;
      'Thu': result := 4;
      'Fri': result := 5;
      'Sat': result := 6;
      'Sun': result := 7;
    end;
  end;

{
calling this function by:
today := dayofweek(formatdate('ddd'));
}
It works perfectly when on English-language server, but on any other it returns 0.

Is there any way to get the number of day of week without language incompabilities?
Title: Re: Day of week
Post by: ~Niko~ on June 06, 2009, 05:38:31 pm
maybe there's some function to check what language has the computer, and depending on which one has, it executes in a different way?
Title: Re: Day of week
Post by: freestyler on June 06, 2009, 06:35:08 pm
maybe there's some function to check what language has the computer
It's not necessary, it's just a matter of day names I put into 'case day of', but it doesn't work all the time (for example, Polish Wednesday is Środa, and that character is unreadable by scripting engine). I am looking for a function that wouldn't use day names for that.
Title: Re: Day of week
Post by: ~Niko~ on June 06, 2009, 06:44:37 pm
you could try turning the name of the day into a Byte... is that possible?
Title: Re: Day of week
Post by: freestyler on June 07, 2009, 02:06:06 am
Look at the script in first post and answer yourself. The trick is not to use the name of day at all.
Title: Re: Day of week
Post by: Gizd on June 07, 2009, 03:23:34 am
FormatDate gets data from pc, so I don't think its possible to get it in english only.
Quote from some program: 'Today is 27 Maj 2009'
Title: Re: Day of week
Post by: JFK on June 07, 2009, 08:11:59 am
It's not necessary, it's just a matter of day names I put into 'case day of', but it doesn't work all the time (for example, Polish Wednesday is Środa, and that character is unreadable by scripting engine). I am looking for a function that wouldn't use day names for that.

You can use ascii numbers to replace certain characters. In this case 'Środa' would become:
Code: [Select]
s : string;
s := #346+'roda';
At least according to this site (http://webdesign.about.com/od/localization/l/blhtmlcodes-pl.htm).
If that doesn't work you could also save all the days in a file and read those as string, that way you don't have to use these characters in your code.

However, the most elegant solution is to forget about names of days at all (supose someone with a chinese platform tries your script). You could try to find(google) or create a formula that will extract the daynumber out of the three date numbers yy mm dd. Hmm.. maybe i'll break my head around that one, might be interesting.

edit:click (http://stason.org/TULARC/society/calendars/2-15-1-Is-there-a-formula-for-calculating-the-Julian-day-nu.html)
Title: Re: [solved] Day of week
Post by: freestyler on June 07, 2009, 09:38:23 am
edit:click (http://stason.org/TULARC/society/calendars/2-15-1-Is-there-a-formula-for-calculating-the-Julian-day-nu.html)
Thank you, it works! :)
Title: Re: [solved] Day of week
Post by: LORD KILLA on June 17, 2009, 08:31:19 am
or just do:
Code: [Select]
FormatDate('d');
// 1000 times easier <.<
Title: Re: [solved] Day of week
Post by: JFK on June 17, 2009, 01:00:50 pm
or just do:
Code: [Select]
FormatDate('d');
// 1000 times easier <.<

ouch.. :p
Title: Re: [solved] Day of week
Post by: freestyler on June 17, 2009, 01:40:32 pm
Um... No? FormatDate('d') returns day of month, not day of week.