The library comes with a special function called DT.TEST(). You can run it by uncommenting the last DT.TEST() line and you can look at it to find out how you can make use of all the provided functions, objects and methods.

Here is the function contents:

  Cls()
  
  NPrint("PART 1 : Convertion Functions")
  NPrint("-----------------------------")
  ; DT.DateToDays()
  ; DT.DaysToDate()
  Local r1 = DT.DateToDays(23, 4, 2016)
  NPrint(" - DT.DateToDays(23, 4, 2016)                  = ", r1)
  Local r1a = DT.DaysToDate(r1, #DT_FORMAT_STANDARD)
  Local r1b, r1c, r1d = DT.DaysToDate(r1, #DT_FORMAT_SEPARATED)
  NPrint(" - DT.DaysToDate(" .. r1 .. ", #DT_FORMAT_STANDARD)  = ", r1a)
  NPrint(" - DT.DaysToDate(" .. r1 .. ", #DT_FORMAT_SEPARATED) = ", r1b, r1c, r1d)
  NPrint("")

  ; DT.IsLeap()
  For Local i = 0 To 5
    Local y = Rnd(3000)
    NPrint(" - " .. y .. " is leap? " .. IIf(DT.IsLeap(y), "YES", "NO"))
  Next
  NPrint("")
  
  ; DT.MillisecondsToTime()
  For Local i = 0 To 5
    Local ms = Rnd(999999999)
    Local v1 = DT.MillisecondsToTime(ms, True)
    Local v2 = DT.MillisecondsToTime(ms, False)
    NPrint(" - DT.MillisecondsToTime(" .. ms .. ", True)   = " .. v1)
    NPrint(" - DT.MillisecondsToTime(" .. ms .. ", False)  = " .. v2)
    NPrint("")
  Next
  
  ; DT.MinutesToTime()
  ; DT.TimeToMinutes()
  Local v1 = DT.TimeToMinutes("57:25")
  Local v2 = DT.MinutesToTime(v1)
  NPrint(" - DT.TimeToMinutes(\"57:25\") = ", v1)
  NPrint(" - DT.MinutesToTime(" .. v2 .. ")   = ", v2)
  NPrint("")
  
  ; DT.TimeToSeconds()
  ; DT.SecondsToTime()
  Local s = DT.TimeToSeconds("14:43:21")
  Local t = DT.SecondsToTime(s)
  NPrint(" - DT.TimeToSeconds('14:43:21') = " .. s)
  NPrint(" - DT.SecondsToTime(" .. s .. ") = " .. t)
  NPrint("")
  
  ; DT.MonthToNumber()
  ; DT.NumberToMonth()
  For Local i = 1 To 12
    Local m = DT.NumberToMonth(i)
    Local n = DT.MonthToNumber(m)
    NPrint(" - DT.NumberToMonth(" .. i .. ") = " .. m .. ", DT.MonthToNumber(" .. m .. ") = " .. n)
  Next
  NPrint("")
  
  ; DT.NDate_AddDays()
  Local d, m, y = DT.NDate_AddDays(21, 2, 2012, 44)
  NPrint(" - DT.NDate_AddDays(21, 2, 2012, 44) = " .. "d:" .. d .. " m:" .. m .. " y:" .. y)
  NPrint("")
  
  ; DT.SDate_AddDays()
  Local s = DT.SDate_AddDays("21-Feb-2012", 44)
  NPrint(" - DT.SDate_AddDays('21-Feb-2012', 44) = " .. s)
  NPrint("")
  
  NPrint("=== Left Mouse Button to continue ===")
  WaitLeftMouse()
  
  Cls()
  Locate(0, 0)
  NPrint("PART 2 : TimeObject")
  NPrint("-------------------")
  
  ; TimeObj:New()
  NPrint(" - Creating a new time object with the current date & time...")
  Local to1 = TimeObj:NewNow()
  NPrint(" --> " .. to1:toString())
  NPrint("")
  
  NPrint(" - Creating a second time object holding 4 hours, 23 minutes and 55 seconds...")
  Local to2 = TimeObj:New({ 0, 0, 0, 4, 23, 55, 0 })
  NPrint(" --> " .. to2:toString())
  NPrint("")
  
  NPrint(" - Add Method : Adding time 1 with time 2 with :Add() method")
  Local to3 = to1:Add(to2)
  NPrint(" --> " .. to3:toString())
  NPrint("")
  
  NPrint(" - Sub Method : Subtracting time 2 from time 1 with :Sub() method")
  Local to4 = to1:Sub(to2)
  NPrint(" --> " .. to4:toString())
  NPrint("")

  NPrint("*** TEST ENDED ***")
  NPrint("Click left mouse button to quit.")

  WaitLeftMouse()
  End
hollywoodlibs/datetime/test.txt · Ultima modifica: 2016/11/08 09:01 da admin
CC Attribution-Noncommercial 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0