Jump to content

The name of any day by date (multilingual)


topsecret
 Share

Recommended Posts

_WhatDayIsIt($date, $language)

Date format: yyyy/mm/dd

Supported languages:

- English = eng

- French = fra

- German = ger

- Hungarian = hun

- Italian = ita

- Portuguese = por

- Romanian = rom

- Spanish = esp

Hy guys, it's simple, maybe pointless, maybe there's an easier way to do it BUT I made a UDF that tells the name of a specified date. You can choose between the 8 languages implemented in the UDF

It works for dates starting from the year 2000.

If it helps, my pleasure, if you know an easier way please leave a comment! ;)

GL & HF while developing :)

DDay.au3

Edited by topsecret
Link to comment
Share on other sites

This is useful, but can be done otherwise for some languages by asking Windows locale info. I have done this in Perl, and surely this is possible under AutoIT also.

However, as stated - Windows only keeps information for some languages, while the more exotic languages are left out.

Your script is simple to extend. But perhaps as it grows it would be simpler to refer to an SQL database ?

A good starting point is at omniglot:

http://www.omniglot.com/language/time/days.htm

http://www.omniglot.com/language/time/months.htm

This is where things get complicated, because many languages have different month / weekday names based on context. The ending is / may be different in "Today is Monday" and "Monday is a great day" and "I will meet you on Monday". etc From what I know, most East-European languages (Polish, Czech, Russian etc) are like that.

There is also a short and long form of days / month names. Again, some of this can be extracted from Locale() info, but not all.

So as I see it, a script like yours should have as option

  • locale
  • short/long form
  • context (optional)
Localization is really interesting, but also more and more complex the more you know :)

I am just a hobby programmer, and nothing great to publish right now.

Link to comment
Share on other sites

Look ghere: http://www.autoit.de/index.php?page=Thread&postID=188817#post188817

#include <Date.au3>
$M = @MON
$T = _DateToDayOfWeekISO(@YEAR, @MON, @MDAY)
MsgBox(0, "Monat " & $M, _Locale_MonthName($M))
MsgBox(0, "Tag " & $T, _Locale_DayName($T, 1))
Exit


Func _Locale_MonthName($Month, $Abbrev = False)
    ; ==========================================================================================
    ; Autor:        Großvater (www.autoit.de)
    ; Parameter:
    ; $Month    -   Nummer des Monats (1 - 12)
    ; $Abbrev   -   abgekürzten Namen liefern:
    ;               |0 : nein
    ;               |1 : ja
    ; ==========================================================================================
    Local Const $LOCALE_USER_DEFAULT = 0x0400
    Local Const $LOCALE_SMONTHNAME = 0x37
    Local Const $LOCALE_SABBREVMONTHNAME = 0x43
    Local $LCType = $LOCALE_SMONTHNAME
    If $Abbrev Then $LCType = $LOCALE_SABBREVMONTHNAME
    If Not StringIsInt($Month) Or $Month < 1 Or $Month > 12 Then Return False
    Local $aResult = DllCall("Kernel32.dll", "Int", "GetLocaleInfoW", _
                            "UInt", $LOCALE_USER_DEFAULT, _
                            "UInt", $LCType + $Month, _
                            "WStr", "", _
                            "Int", 80)
    If @error Or $aResult[0] = 0 Then Return False
    Return $aResult[3]
EndFunc


Func _Locale_DayName($WDay, $Abbrev = False)
    ; ==========================================================================================
    ; Autor:        Großvater (www.autoit.de)
    ; Parameter:
    ; $WDay     -   Nummer des Wochentages (1 - 7) (!!! 1 ist Montag (s.u.) !!!)
    ; $Abbrev   -   abgekürzten Namen liefern:
    ;               |0 : nein
    ;               |1 : ja
    ; Anmerkungen:
    ; Zu meinem Erstaunen hat MS in WinNLS.h folgende Konstanten definiert:
    ;   #define LOCALE_SDAYNAME1              0x0000002A   // long name for Monday
    ;   ...
    ;   #define LOCALE_SDAYNAME7              0x00000030   // long name for Sunday
    ; Anders als beim Macro @WDAY gilt deshalb der Montag als Tag 1 und der Sonntag
    ; als Tag 7. Der passende Wert lässt sich per Aufruf der UDF-Funktion
    ;       _DateToDayOfWeekISO()
    ; ermitteln.
    ; ==========================================================================================
    Local Const $LOCALE_USER_DEFAULT = 0x0400
    Local Const $LOCALE_SDAYNAME = 0x29
    Local Const $LOCALE_SABBREVDAYNAME = 0x30
    Local $LCType = $LOCALE_SDAYNAME
    If $Abbrev Then $LCType = $LOCALE_SABBREVDAYNAME
    If Not StringIsInt($WDay) Or $WDay < 1 Or $WDay > 7 Then Return False
    Local $aResult = DllCall("Kernel32.dll", "Int", "GetLocaleInfoW", _
                            "UInt", $LOCALE_USER_DEFAULT, _
                            "UInt", $LCType + $WDay, _
                            "WStr", "", _
                            "Int", 80)
    If @error Or $aResult[0] = 0 Then Return False
    Return $aResult[3]
EndFunc

#include <Date.au3>
$M = @MON
$T = _DateToDayOfWeekISO(@YEAR, @MON, @MDAY)
MsgBox(0, "Monat " & $M, _Locale_MonthName($M, 0, 0x0406))
MsgBox(0, "Tag " & $T, _Locale_DayName($T, 0, 0x0406))
Exit


Func _Locale_MonthName($Month, $Abbrev = False, $LCID = "")
    ; ==========================================================================================
    ; Autor:        Großvater (www.autoit.de)
    ; Parameter:
    ; $Month    -   Nummer des Monats (1 - 12)
    ; $Abbrev   -   abgekürzten Namen liefern:
    ;               |0 : nein
    ;               |1 : ja
    ; $LCID     -   Sprachbezeichner gem. Abschnitt "@OSLang values" im Anhang der Hilfedatei
    ;               als 16-bittiger Hexwert: 0xnnnn (z.b. 0x0407 für Deutschland).
    ;               Bei fehlender Angabe wird die Defaulteinstellung  des Benutzers verwendet.
    ; ==========================================================================================
    Local Const $LOCALE_USER_DEFAULT = 0x0400
    Local Const $LOCALE_SMONTHNAME = 0x37
    Local Const $LOCALE_SABBREVMONTHNAME = 0x43
    Local $LCType = $LOCALE_SMONTHNAME
    If $Abbrev Then $LCType = $LOCALE_SABBREVMONTHNAME
    If $LCID = "" Then $LCID = $LOCALE_USER_DEFAULT
    If Not StringIsInt($Month) Or $Month < 1 Or $Month > 12 Then Return False
    Local $aResult = DllCall("Kernel32.dll", "Int", "GetLocaleInfoW", _
                            "UInt", $LCID, _
                            "UInt", $LCType + $Month, _
                            "WStr", "", _
                            "Int", 80)
    If @error Or $aResult[0] = 0 Then Return False
    Return $aResult[3]
EndFunc


Func _Locale_DayName($WDay, $Abbrev = False, $LCID = "")
    ; ==========================================================================================
    ; Autor:        Großvater (www.autoit.de)
    ; Parameter:
    ; $WDay     -   Nummer des Wochentages (1 - 7) (!!! 1 ist Montag (s.u.) !!!)
    ; $Abbrev   -   abgekürzten Namen liefern:
    ;               |0 : nein
    ;               |1 : ja
    ; $LCID     -   Sprachbezeichner gem. Abschnitt "@OSLang values" im Anhang der Hilfedatei
    ;               als 16-bittiger Hexwert: 0xnnnn (z.b. 0x0407 für Deutschland).
    ;               Bei fehlender Angabe wird die Defaulteinstellung  des Benutzers verwendet.
    ; Anmerkungen:
    ; Zu meinem Erstaunen hat MS in WinNLS.h folgende Konstanten definiert:
    ;   #define LOCALE_SDAYNAME1              0x0000002A   // long name for Monday
    ;   ...
    ;   #define LOCALE_SDAYNAME7              0x00000030   // long name for Sunday
    ; Anders als beim Macro @WDAY gilt deshalb der Montag als Tag 1 und der Sonntag
    ; als Tag 7. Der passende Wert lässt sich per Aufruf der UDF-Funktion
    ;       _DateToDayOfWeekISO()
    ; ermitteln.
    ; ==========================================================================================
    Local Const $LOCALE_USER_DEFAULT = 0x0400
    Local Const $LOCALE_SDAYNAME = 0x29
    Local Const $LOCALE_SABBREVDAYNAME = 0x30
    If $LCID = "" Then $LCID = $LOCALE_USER_DEFAULT
    Local $LCType = $LOCALE_SDAYNAME
    If $Abbrev Then $LCType = $LOCALE_SABBREVDAYNAME
    If $LCID = "" Then $LCID = $LOCALE_USER_DEFAULT
    If Not StringIsInt($WDay) Or $WDay < 1 Or $WDay > 7 Then Return False
    Local $aResult = DllCall("Kernel32.dll", "Int", "GetLocaleInfoW", _
                            "UInt", $LCID, _
                            "UInt", $LCType + $WDay, _
                            "WStr", "", _
                            "Int", 80)
    If @error Or $aResult[0] = 0 Then Return False
    Return $aResult[3]
EndFunc

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

Hy guys, thanks for sharing your opinion on my script. I know it's small, I know it's simple but I wrote it in 10-15 minutes or so. While writing an other script I encountered this dayname problem, got around it and thought I should make a simple UDF for everybody out there who wants a simple way to call the dayname of a given date. I wasn't really looking forward to extending it or anything but I think I'll implement the things you said Myicq, thanks for the tips!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...