Author Topic: [solved] Day of week  (Read 1180 times)

0 Members and 1 Guest are viewing this topic.

Offline freestyler

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 326
[solved] Day of week
« 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?
« Last Edit: June 07, 2009, 09:38:40 am by freestyler »

Offline ~Niko~

  • Rainbow Warrior
  • *****
  • Posts: 2410
Re: Day of week
« Reply #1 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?

Offline freestyler

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 326
Re: Day of week
« Reply #2 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.

Offline ~Niko~

  • Rainbow Warrior
  • *****
  • Posts: 2410
Re: Day of week
« Reply #3 on: June 06, 2009, 06:44:37 pm »
you could try turning the name of the day into a Byte... is that possible?

Offline freestyler

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 326
Re: Day of week
« Reply #4 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.

Offline Gizd

  • Flagrunner
  • ****
  • Posts: 586
  • (Re)tired
    • Eat-this! community site
Re: Day of week
« Reply #5 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'

Offline JFK

  • Camper
  • ***
  • Posts: 255
    • My TraxInSpace Account
Re: Day of week
« Reply #6 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.
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
« Last Edit: June 07, 2009, 08:17:16 am by JFK »
Come join: EliteCTF
Listen to: My Music

Offline freestyler

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 326
Re: [solved] Day of week
« Reply #7 on: June 07, 2009, 09:38:23 am »

Offline LORD KILLA

  • Camper
  • ***
  • Posts: 254
  • Happie
Re: [solved] Day of week
« Reply #8 on: June 17, 2009, 08:31:19 am »
or just do:
Code: [Select]
FormatDate('d');
// 1000 times easier <.<

Offline JFK

  • Camper
  • ***
  • Posts: 255
    • My TraxInSpace Account
Re: [solved] Day of week
« Reply #9 on: June 17, 2009, 01:00:50 pm »
or just do:
Code: [Select]
FormatDate('d');
// 1000 times easier <.<

ouch.. :p
Come join: EliteCTF
Listen to: My Music

Offline freestyler

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 326
Re: [solved] Day of week
« Reply #10 on: June 17, 2009, 01:40:32 pm »
Um... No? FormatDate('d') returns day of month, not day of week.