• 0

    posted a message on Comparing dates in lua
    Unfortunately, I need date and time information based on the current server time, so I cannot use date() or time(). This would be a non-issue but the database has syncing features so having different returns for people in different time zones will cause issues.

    Edit: With that said, is there a way to retrieve seconds from the server time? CalendarGetDate() can return the correct date information, and GetGameTime() returns the hour and minute - but I do not see anything for seconds. It's not a big issue, but exact time would be lovely.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Comparing dates in lua
    Thank you all for your very informative answers.

    Quote from OrionShock
    *b/c chrome won't let me edit my post..

    using time() instead of date() is better because you can feed the values from time() into date(). when you use date() you can feed in any display format you want.

    Dump: value=time()
    [1]=1270172773
    Dump: value=date("%c", time())
    [1]="04/01/10 18:46:17"


    time() would be an excellent solution, but I need the server time instead of the local time.

    Quote from Farmbuyer
    That's because 0>3 is false, and so the comparison need go no further.

    You have a string, not a number, and strings are compared alphabetically one character at a time. (Well, lexigraphically, actually, but the distinction is a fine one here.) That means the same number of digits for each category; whether that be 1 or 2 or 4, it must be the same for both left and right sides. You have a leading zero on one side but not on the other, so everything stops at the very first "digit" character.

    Like others have said, by making the format uniform and always largest-unit to smallest-unit, alphabetical sorting becomes numeric sorting, and all these problems just go away.


    For single digit hours: GetGameTime() returns without a leading zero, and I had not taken that into account. Thank you for the in-depth explanation, though. =)

    I'm going to go with the YYYY-MM-DD hh:mm:ss format, which I had completely overlooked since I'm so used to MM-DD-YYYY format.

    Thanks again, everyone!
    Posted in: Lua Code Discussion
  • 0

    posted a message on Comparing dates in lua
    I had only tested the comparisons with the forward slashes as delimiters for the dates before I made this thread. It seems that I was over-complicating the issue. :D

    Thank you both for your quick answers!

    Edit: Perhaps I wasn't, unfortunately. :(

    "04:01:2010 12:00:00" > "3:30:2010 12:00:00" => false
    Posted in: Lua Code Discussion
  • 0

    posted a message on Comparing dates in lua
    I think I'll just use colons as the delimiter.

    "04/01/2010" > "04/02/2010" => false
    "04/03/2010" > "04/02/2010" => true
    "04/03/2010" > "04/05/2010" => false
    "04/03/2010" > "04/05/2009" => false
    "07:58:59" > "8:00:00" => false
    "07:58:59" > "08:00:00" => false
    "09:58:59" > "08:00:00" => true
    "08:00:01" > "08:00:00" => true
    "08:00:01" > "08:00:02" => false
    "24:00:01" > "08:24:02" => true
    "15:03:04" == "15:03:04" => true
    "15:03:04" == "15:03:05" => false
    "15:03:04" < "15:03:05" => true
    "15:03:04" > "15:03:05" => false
    "15:03:04" >= "15:03:05" => false
    "15:03:04" <= "15:03:05" => true
    "04:01:2010" > "04:02:2010" => false
    "04:01:2010" > "04:00:2010" => true
    "04:01:2010 3:52:25" > "04:01:2010 3:53:25" => false
    "04:01:2010 3:52:25" < "04:01:2010 3:53:25" => true
    "04:01:2010 3:52:25" < "04:01:2010 3:52:25" => false
    "04:01:2010 3:52:25" < "04:01:2010 3:52:26" => true
    
    Posted in: Lua Code Discussion
  • 0

    posted a message on Comparing dates in lua
    I've created a loot database addon for my guild, and they would prefer for it to be sorted by date. The problem is that I have not found any way to compare dates in lua.

    local Timestamp = date("%m/%d/%Y " .. GetGameTime() .. ":%M:%S")
    local Month, Day, Year, Hour, Minute, Second = string.match(Timestamp, "(%w-)/(%w-)/(%w-) (%w-):(%w-):(%w-)$")


    Is there something I overlooked in my search, or is the above one of the methods I may need to employ in order to achieve this? =)

    Edit: After some experimenting in game, it seems I may have created this thread prematurely. Comparing strings of time seems to return accurate bool values, but comparing dates did not.
    Posted in: Lua Code Discussion
  • 0

    posted a message on [Grid] Modules: Threat,RaidIcons,MTs / Indicators: Text3,SideIcons
    Quote from kunda
    Please update Grid, e.g. r1282 - http://www.wowace.com/addons/grid/files/.


    I'm already using the latest version of Grid (r1282) and the latest version of GridIndicatorSideIcons (r49). I tried r48 of GridIndicatorSideIcons as well, but it did not change anything.
    Posted in: Grid & Grid2
  • 0

    posted a message on [Grid] Modules: Threat,RaidIcons,MTs / Indicators: Text3,SideIcons
    Any chance of getting GridIndicatorSideIcons fixed to work with the latest version of Grid? I tried to debug it myself, but switching to r48 or tinkering with the newer module support method did not seem to change its decision to not show at all. :(
    Posted in: Grid & Grid2
  • 0

    posted a message on Local Function ...Optimization!
    I've noticed some authors have their own approach to how they handle functions.
    local AddOn = CreateFrame("Frame")
    function AddOn:Function() end
    


    Out of curiousity, are functions stored in tables considered global unless they're pointing to a local function such as:

    local AddOn = CreateFrame("Frame")
    local function Function() end
    
    AddOn.Function = Function
    


    Or do they inherit the local property from the table itself? Would this also apply to functions passed as an argument to another function?

    local AddOn = CreateFrame("Frame")
    local function Function() end
    AddOn:SetScript("Whatever", Function)
    


    local AddOn = CreateFrame("Frame")
    AddOn:SetScript("Whatever", function() end)
    
    Posted in: Lua Code Discussion
  • 0

    posted a message on Local Variable Optimization
    Thanks for the replies. :) That's about all I needed to know.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Local Variable Optimization
    Quote from Arrowmaster
    No you are wrong.


    Why is he wrong, though?

    Quote from Flickor
    There would be two reasons why you should use the local variable outside the function:
    1. If that function is called VERY often (like from a onupdate script or a heavy event like CLEU or UNIT_AURA)
    2. If you are going to use the same variable in multiple functions or somewhere else in your code.


    I'm aware of the purpose for declaring it outside or inside of the function. I'm not aware of the actual amount of time/memory I would save by doing one or the other. I'm assuming the time will be negligible, but would the memory be? Am I assuming incorrectly? Pie or cake?
    Posted in: Lua Code Discussion
  • 0

    posted a message on Local Variable Optimization
    I've been curious about this for a while now. Assuming scope is not an issue, would it be faster to do:

    local Variable1, Variable2
    
    local function Func()
       Variable1 = something...
       Variable2 = something else...
    end
    


    Or:

    local function Func()
       local Variable1 = something...
       local Variable2 = something else...
    end
    


    Or, would the speed be equal? Also, would the first method be more memory efficient than the second method?
    Posted in: Lua Code Discussion
  • To post a comment, please or register a new account.