Buchempfehlung
MySQL kurz & gut
MySQL kurz & gut
Das preiswerte Taschen- buch stellt MySQL-rele- vante Inhalte systematisch und knapp dar, sodass es sich optimal zum Nach- schlagen beim Pro- grammieren eignet. [Mehr Infos...]
FreeBASIC-Chat
Es sind Benutzer im FreeBASIC-Chat online.
(Stand:  )
FreeBASIC bei Twitter
Twitter FreeBASIC-Nachrichten jetzt auch über Twitter erhalten. Follow us!

fb:porticula NoPaste

Info
Info / Hilfe
Liste
Übersicht / Liste
Neu
Datei hochladen
Suche
Quellcode suchen
Download
Dateidownload

Alternative bestimmung des Tagesnamen

Uploader:MitgliedStueber
Datum/Zeit:11.05.2010 20:00:38

#define FBDATE_Jan 0

#define FBDATE_Feb 3

#define FBDATE_Mae 3

#define FBDATE_Apr 6

#define FBDATE_Mai 1

#define FBDATE_Jun 4

#define FBDATE_Jul 6

#define FBDATE_Aug 2

#define FBDATE_Sep 5

#define FBDATE_Okt 0

#define FBDATE_Nov 3

#define FBDATE_Dez 5



#define FBDATE_MONTAG 1

#define FBDATE_DIENSTAG 2

#define FBDATE_MITTWOCH 3

#define FBDATE_DONNERSTAG 4

#define FBDATE_FREITAG 5

#define FBDATE_SAMSTAG 6

#define FBDATE_SONNTAG 7





type FBDate

    declare constructor ()

    declare constructor (byval d as string)

    declare constructor (byval t as string, byval m as string, byval y as string)

    datum as string



    declare function getDay() as integer

    declare function getDayOfWeek() as integer

    declare function getDayOfYear() as integer

    declare function dayName() as integer



    declare function getYear() as integer



    declare function getMonth() as integer



    declare function daysInYear() as integer

    declare function daysInMonth() as integer



    declare function leapYear() as integer

    declare function isValid () as integer



    declare function addDay(byval i as integer = 0) as FBDate

    declare function addMonth(byval i as integer = 0) as FBDate

    declare function addYear(byval i as integer = 0) as FBDate



    declare static function currentDate () as FBDate

    declare static function isValid (byval d as string) as integer

end type









constructor FBDate ()

    datum = date

end constructor





constructor FBDate(byval d as string)

    datum = d

end constructor





constructor FBDate (byval t as string, byval m as string, byval y as string)

    datum = m + "-" + t + "-" + y

end constructor





function FBDate.getDay() as integer

    dim as string d = datum

    d = mid(d,4,2)

    return val(d)

end function





function FBDate.getDayOfWeek() as integer

    return dayName()

end function





function FBDate.getDayOfYear() as integer

    dim as integer m = getMonth()

    dim as integer tag = 0

    if m > 1 then tag = tag + 31

    if m = 1 then tag = tag + getDay()

    if m > 2 and getYear() mod 4 = 0 then tag = tag + 29

    if m = 2 and getYear() mod 4 = 0 then tag = tag + getDay()

    if m > 2 and getYear() mod 4 <> 0 then tag = tag + 28

    if m = 2 and getYear() mod 4 <> 0 then tag = tag + getDay()

    if m > 3 then tag = tag + 31

    if m = 3 then tag = tag + getDay()

    if m > 4 then tag = tag + 30

    if m = 4 then tag = tag + getDay()

    if m > 5 then tag = tag + 31

    if m = 5 then tag = tag + getDay()

    if m > 6 then tag = tag + 30

    if m = 6 then tag = tag + getDay()

    if m > 7 then tag = tag + 31

    if m = 7 then tag = tag + getDay()

    if m > 8 then tag = tag + 31

    if m = 8 then tag = tag + getDay()

    if m > 9 then tag = tag + 30

    if m = 9 then tag = tag + getDay()

    if m > 10 then tag = tag + 31

    if m = 10 then tag = tag + getDay()

    if m > 11 then tag = tag + 30

    if m = 11 then tag = tag + getDay()

    if m > 12 then tag = tag + 31

    if m = 12 then tag = tag + getDay()



    return tag

end function





function FBDate.dayName() as integer

    dim t as integer = getDay() mod 7



    dim as string d2 = datum

    d2 = mid(d2,9,2)

    dim as integer j = val(d2)

    j = (j + (val(d2) / 4)) mod 7



    d2 = datum

    d2 = mid(d2,7,2)

    dim as integer jh = val(d2)

    jh = (3 - jh mod 4) * 2



    d2 = datum

    d2 = mid(d2,1,2)

    dim as integer m = val(d2)

    dim sch as integer = 0

    if m < 3 and (getYear() mod 4 = 0) then sch = -1



    dim monat as integer = getMonth()

    if monat = 1 then

        monat = FBDATE_Jan

    elseif monat = 2 then

        monat= FBDATE_Feb

    elseif monat = 3 then

        monat= FBDATE_Mae

    elseif monat = 4 then

        monat= FBDATE_Apr

    elseif monat = 5 then

        monat= FBDATE_Mai

    elseif monat = 6 then

        monat= FBDATE_Jun

    elseif monat = 7 then

        monat= FBDATE_Jul

    elseif monat = 8 then

        monat= FBDATE_Aug

    elseif monat = 9 then

        monat= FBDATE_Sep

    elseif monat = 10 then

        monat= FBDATE_Okt

    elseif monat = 11 then

        monat= FBDATE_Nov

    elseif monat = 12 then

        monat= FBDATE_Dez

    end if



    dim as integer r = (sch + jh + j +t + monat) mod 7

    if r = 0 then r = 7

    return r

end function





function FBDate.getYear() as integer

    dim as string d = datum

    d = mid(d,7,4)

    return val(d)

end function





function FBDate.getMonth() as integer

    dim as string d = datum

    d = mid(d,1,2)

    return val(d)

end function





function FBDate.daysInYear() as integer

    if getYear() mod 4 = 0 then return 366

    return 365

end function





function FBDate.daysInMonth() as integer

    dim monat as integer = getMonth()

    if monat = 1 then

        return 31

    elseif monat = 2 then

        if daysInYear() = 366 then return 29

        return 28

    elseif monat = 3 then

        return 31

    elseif monat = 4 then

        return 30

    elseif monat = 5 then

        return 31

    elseif monat = 6 then

        return 30

    elseif monat = 7 then

        return 31

    elseif monat = 8 then

        return 31

    elseif monat = 9 then

        return 30

    elseif monat = 10 then

        return 31

    elseif monat = 11 then

        return 30

    elseif monat = 12 then

        return 31

    end if

end function





function FBDate.leapYear() as integer

    if daysInYear() = 366 then return -1

    return 0

end function





function FBDate.isValid () as integer

    dim as integer tag = 0,monat = 0,jahr = 0

    dim as string s

    s = mid(datum,1,2)

    monat = val(s)



    s = mid(datum,4,2)

    tag = val(s)



    s = mid(datum,7,4)

    jahr = val(s)



    if monat = 1 and tag >= 1 and tag <= 31 then return -1

    if monat = 2 and tag >= 1 and tag <= 28 then return -1

    if monat = 2 and tag = 29 and jahr mod 4 = 0 then return -1

    if monat = 3 and tag >= 1 and tag <= 31 then return -1

    if monat = 4 and tag >= 1 and tag <= 30 then return -1

    if monat = 5 and tag >= 1 and tag <= 31 then return -1

    if monat = 6 and tag >= 1 and tag <= 30 then return -1

    if monat = 7 and tag >= 1 and tag <= 31 then return -1

    if monat = 8 and tag >= 1 and tag <= 31 then return -1

    if monat = 9 and tag >= 1 and tag <= 30 then return -1

    if monat = 10 and tag >= 1 and tag <= 31 then return -1

    if monat = 11 and tag >= 1 and tag <= 30 then return -1

    if monat = 12 and tag >= 1 and tag <= 31 then return -1

    return 0

end function





function FBDate.currentDate () as FBDate

    return FBDate()

end function





function FBDate.isValid (byval d as string) as integer

    dim as integer tag = 0,monat = 0,jahr = 0

    dim as string s

    s = mid(d,1,2)

    monat = val(s)



    s = mid(d,4,2)

    tag = val(s)



    s = mid(d,7,4)

    jahr = val(s)



    if monat = 1 and tag >= 1 and tag <= 31 then return -1

    if monat = 2 and tag >= 1 and tag <= 28 then return -1

    if monat = 2 and tag = 29 and jahr mod 4 = 0 then return -1

    if monat = 3 and tag >= 1 and tag <= 31 then return -1

    if monat = 4 and tag >= 1 and tag <= 30 then return -1

    if monat = 5 and tag >= 1 and tag <= 31 then return -1

    if monat = 6 and tag >= 1 and tag <= 30 then return -1

    if monat = 7 and tag >= 1 and tag <= 31 then return -1

    if monat = 8 and tag >= 1 and tag <= 31 then return -1

    if monat = 9 and tag >= 1 and tag <= 30 then return -1

    if monat = 10 and tag >= 1 and tag <= 31 then return -1

    if monat = 11 and tag >= 1 and tag <= 30 then return -1

    if monat = 12 and tag >= 1 and tag <= 31 then return -1

    return 0

end function





function FBDate.addDay(byval i as integer) as FBDate

    dim as integer tag = 0,monat = 0,jahr = 0

    dim as string s

    dim z as integer = 0

    s = mid(datum,1,2)

    monat = val(s)



    s = mid(datum,4,2)

    tag = val(s)



    s = mid(datum,7,4)

    jahr = val(s)



    if i < 1 then return FBDate(datum)



    do

        z = z + 1

        tag = tag + 1

        if monat = 1 and tag = 32 then tag = 1 : monat = monat + 1

        if monat = 2 and tag = 29 and jahr mod 4 <> 0 then tag = 1 : monat = monat + 1

        if monat = 2 and tag = 30 and jahr mod 4 = 0 then tag = 1 : monat = monat + 1

        if monat = 3 and tag = 32 then tag = 1 : monat = monat + 1

        if monat = 4 and tag = 31 then tag = 1 : monat = monat + 1

        if monat = 5 and tag = 32 then tag = 1 : monat = monat + 1

        if monat = 6 and tag = 31 then tag = 1 : monat = monat + 1

        if monat = 7 and tag = 32 then tag = 1 : monat = monat + 1

        if monat = 8 and tag = 32 then tag = 1 : monat = monat + 1

        if monat = 9 and tag = 31 then tag = 1 : monat = monat + 1

        if monat = 10 and tag = 32 then tag = 1 : monat = monat + 1

        if monat = 11 and tag = 31 then tag = 1 : monat = monat + 1

        if monat = 12 and tag = 32 then tag = 1 : monat = monat + 1



        if monat = 13 then monat = 1 : jahr = jahr + 1



        s = "00-00-0000"

        if tag < 10 then

            mid(s,5,1) = str(tag)

        else

            mid(s,4,2) = str(tag)

        end if



        if monat < 10 then

            mid(s,2,1) = str(monat)

        else

            mid(s,1,2) = str(monat)

        end if



        if jahr < 10 then

            mid(s,10,1) = str(jahr)

        elseif jahr < 100 then

            mid(s,9,2) = str(jahr)

        elseif jahr < 1000 then

            mid(s,8,3) = str(jahr)

        elseif jahr < 10000 then

            mid(s,7,4) = str(jahr)

        end if

    loop until z = i

    return FBDate(s)

end function





function FBDate.addMonth(byval i as integer) as FBDate

    dim as integer tag = 0,monat = 0,jahr = 0

    dim as string s

    dim as integer z = 0

    s = mid(datum,1,2)

    monat = val(s)



    s = mid(datum,4,2)

    tag = val(s)



    s = mid(datum,7,4)

    jahr = val(s)



    if i < 1 then return FBDate(datum)



    do

        monat = monat + 1

        z = z + 1

        if monat = 13 then monat = 1 : jahr = jahr + 1

        if monat = 1 and tag = 32 then tag = 1

        if monat = 2 and tag = 29 and jahr mod 4 <> 0 then tag = tag - 1

        if monat = 2 and tag = 30 and jahr mod 4 = 0 then tag = tag - 1

        if monat = 2 and tag = 31 and jahr mod 4 <> 0 then tag = 28

        if monat = 2 and tag = 31 and jahr mod 4 = 0 then tag = 29

        if monat = 3 and tag = 32 then tag = tag - 1

        if monat = 4 and tag = 31 then tag = tag - 1

        if monat = 5 and tag = 32 then tag = tag - 1

        if monat = 6 and tag = 31 then tag = tag - 1

        if monat = 7 and tag = 32 then tag = tag - 1

        if monat = 8 and tag = 32 then tag = tag - 1

        if monat = 9 and tag = 31 then tag = tag - 1

        if monat = 10 and tag = 32 then tag = tag - 1

        if monat = 11 and tag = 31 then tag = tag - 1

        if monat = 12 and tag = 32 then tag = tag - 1



        s = "00-00-0000"

        if tag < 10 then

            mid(s,5,1) = str(tag)

        else

            mid(s,4,2) = str(tag)

        end if



        if monat < 10 then

            mid(s,2,1) = str(monat)

        else

            mid(s,1,2) = str(monat)

        end if



        if jahr < 10 then

            mid(s,10,1) = str(jahr)

        elseif jahr < 100 then

            mid(s,9,2) = str(jahr)

        elseif jahr < 1000 then

            mid(s,8,3) = str(jahr)

        elseif jahr < 10000 then

            mid(s,7,4) = str(jahr)

        end if

    loop until i = z

    return FBDate(s)

end function





function FBDate.addYear(byval i as integer) as FBDate

    dim as integer tag = 0,monat = 0,jahr = 0

    dim as string s

    dim as integer z = 0



    s = mid(datum,1,2)

    monat = val(s)



    s = mid(datum,4,2)

    tag = val(s)



    s = mid(datum,7,4)

    jahr = val(s)



    if i < 1 then return FBDate(datum)



    do

        jahr = jahr + 1

        z = z + 1

        s = "00-00-0000"

        if tag < 10 then

            mid(s,5,1) = str(tag)

        else

            mid(s,4,2) = str(tag)

        end if



        if monat < 10 then

            mid(s,2,1) = str(monat)

        else

            mid(s,1,2) = str(monat)

        end if



        if jahr < 10 then

            mid(s,10,1) = str(jahr)

        elseif jahr < 100 then

            mid(s,9,2) = str(jahr)

        elseif jahr < 1000 then

            mid(s,8,3) = str(jahr)

        elseif jahr < 10000 then

            mid(s,7,4) = str(jahr)

        end if

    loop until i = z



    return FBDate(s)

end function









operator > (byval d1 as FBDate,byval d2 as FBDate) as integer

    if d1.getYear() > d2.getYear() then

        return -1

    end if

    if d1.getYear() = d2.getYear() and d1.getMonth() > d2.getMonth() then

        return -1

    end if

    if d1.getYear() = d2.getYear() and d1.getMonth() = d2.getMonth() and d1.getDay() > d2.getDay() then

        return -1

    end if

    return 0

end operator





operator < (byval d2 as FBDate,byval d1 as FBDate) as integer

    if d1.getYear() > d2.getYear() then

        return -1

    end if

    if d1.getYear() = d2.getYear() and d1.getMonth() > d2.getMonth() then

        return -1

    end if

    if d1.getYear() = d2.getYear() and d1.getMonth() = d2.getMonth() and d1.getDay() > d2.getDay() then

        return -1

    end if

    return 0

end operator





operator >= (byval d1 as FBDate,byval d2 as FBDate) as integer

    if d1.getYear() > d2.getYear() then

        return -1

    end if

    if d1.getYear() = d2.getYear() and d1.getMonth() > d2.getMonth() then

        return -1

    end if

    if d1.getYear() = d2.getYear() and d1.getMonth() = d2.getMonth() and d1.getDay() > d2.getDay() then

        return -1

    end if

    if d1.getYear() = d2.getYear() and d1.getMonth() = d2.getMonth() and d1.getDay() = d2.getDay() then

        return -1

    end if



    return 0

end operator





operator <= (byval d2 as FBDate,byval d1 as FBDate) as integer

    if d1.getYear() > d2.getYear() then

        return -1

    end if

    if d1.getYear() = d2.getYear() and d1.getMonth() > d2.getMonth() then

        return -1

    end if

    if d1.getYear() = d2.getYear() and d1.getMonth() = d2.getMonth() and d1.getDay() > d2.getDay() then

        return -1

    end if

    if d1.getYear() = d2.getYear() and d1.getMonth() = d2.getMonth() and d1.getDay() = d2.getDay() then

        return -1

    end if



    return 0

end operator





operator = (byval d1 as FBDate,byval d2 as FBDate) as integer

    if d1.getYear() = d2.getYear() and d1.getMonth() = d2.getMonth() and d1.getDay() = d2.getDay() then

        return -1

    end if



    return 0

end operator





operator <> (byval d1 as FBDate,byval d2 as FBDate) as integer

    if d1.getYear() <> d2.getYear() or d1.getMonth() <> d2.getMonth() or d1.getDay() <> d2.getDay() then

        return -1

    end if



    return 0

end operator