Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Working Time Module
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
beard0




PostPosted: Fri May 28, 2004 8:48 am   Post subject: Working Time Module

I have found that the Time module in turing doesn't work as well as it should - and the information in the Help file gives wrong info for the Time.SecParts function. I made a module that exports
Date.
Year, Month, Day, Hour, LeapYear, Minute, Second, DayWeek, NameDayWeek, NameMonth
As separate functions, all int values except NameDayWeek, and NameMonth (strings).
Here it is:
code:

module Date
    export Year, Month, Day, Hour, LeapYear, Minute, Second, DayWeek, NameDayWeek, NameMonth

    function LeapYear (y : int) : boolean
        var lp := false
        if y mod 4 = 0 then
            lp := true
            if y mod 100 = 0 then
                lp := false
                if y mod 400 = 0 then
                    lp := true
                    if y mod 4000 = 0 then
                        lp := false
                        if (y - 200) mod 900 = 0 or (y + 600) mod 900 = 0 then
                            lp := true
                        end if
                    end if
                end if
            end if
        end if
        result lp
    end LeapYear

    function Year : int
        var x := Time.Sec
        var year := 1970
        loop
            var leap := 0
            if LeapYear (year) then
                leap := 1
            end if
            exit when x - (365 + leap) * 24 * 60 * 60 < 0
            x -= (365 + leap) * 24 * 60 * 60
            year += 1
        end loop
        result year
    end Year

    function yeardays : int
        var x := Time.Sec
        var year := 1970
        loop
            var leap := 0
            if LeapYear (year) then
                leap := 1
            end if
            exit when x - (365 + leap) * 24 * 60 * 60 < 0
            x -= (365 + leap) * 24 * 60 * 60
            year += 1
        end loop
        result x div 60 div 60 div 24 + 1
    end yeardays

    function Month : int
        var month, day, dayOfWeek, hour, minute, second, blank : int
        Time.SecParts (Time.Sec, day, month, blank, dayOfWeek, hour, minute, second)
        result month
    end Month

    function NameMonth : string
        var months : array 1 .. 12 of string := init ("January", "February", "March", "April", "May", "June", "July", "August", "September", "Octobre", "November", "December")
        result months (Month)
    end NameMonth

    function Day : int
        var month, day, dayOfWeek, hour, minute, second, blank : int
        Time.SecParts (Time.Sec, day, month, blank, dayOfWeek, hour, minute, second)
        result day
    end Day

    function Hour : int
        var month, day, dayOfWeek, hour, minute, second, blank : int
        Time.SecParts (Time.Sec, day, month, blank, dayOfWeek, hour, minute, second)
        result hour
    end Hour

    function Minute : int
        var month, day, dayOfWeek, hour, minute, second, blank : int
        Time.SecParts (Time.Sec, day, month, blank, dayOfWeek, hour, minute, second)
        result minute
    end Minute

    function Second : int
        var month, day, dayOfWeek, hour, minute, second, blank : int
        Time.SecParts (Time.Sec, day, month, blank, dayOfWeek, hour, minute, second)
        result second
    end Second

    function DayWeek : int
        var month, day, dayOfWeek, hour, minute, second, blank : int
        Time.SecParts (Time.Sec, day, month, blank, dayOfWeek, hour, minute, second)
        result dayOfWeek
    end DayWeek

    function NameDayWeek : string
        var days : array 1 .. 7 of string (10) := init ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
        result days (DayWeek)
    end NameDayWeek

end Date
Sponsor
Sponsor
Sponsor
sponsor
guruguru




PostPosted: Fri May 28, 2004 3:33 pm   Post subject: (No subject)

Looks interesting. I havent tried it, but it seems very similar to the Time module that Turing currently has. You stated that such functions as Time.SecParts was faulty, yet you use it!?! It would be awsome if you made your own time module using no non-Turing built-in libraries Very Happy.
beard0




PostPosted: Fri May 28, 2004 5:52 pm   Post subject: (No subject)

It's only part of the Time.SecParts that doesn't work - I use the parts that do - and it's mainly the turing help file that's screwed up
the_short1




PostPosted: Sat Jun 12, 2004 5:38 pm   Post subject: (No subject)

look like u put some erffort into it... good job! + BITS
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: