• Print

Author Topic: Improve timestamp  (Read 9 times)

0 Members and 1 Guest are viewing this topic.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Improve timestamp
« on: October 29, 2006, 08:51:26 pm »
Hey spbogie, love your timestamps for the logs, but do you think you could generalize the function?

Instead of being limited to returning the timestamp for the current time, make it so it can do the timestamp for any number.

Also, instead of using this:
Code: Lua
  1.         local s = math.floor(_CurTime())
  2.         s=tostring(s)
  3.         m=tostring(m)
  4.         h=tostring(h)
  5.         if string.len(s)==1 then s = "0"..s end
  6.         if string.len(m)==1 then m = "0"..m end
  7.         if string.len(h)==1 then h = "0"..h end
  8.  

You can accomplish the same thing more efficiently with this:
Code: Lua
  1.         s = string.format( "%02i", s )
  2.         m = string.format( "%02i", m )
  3.         h = string.format( "%02i", h )
  4.  

Lastly, please move the function from util.lua to misc.lua. (util.lua is for GMod9-only functions, misc.lua is for functions that could run apart from GMod9).

I'd do all this myself, but you know the system better and I thought you might want to handle it.  ;)

Thank you!
Experiencing God's grace one day at a time.

Offline spbogie

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 456
  • Karma: 41
Re: Improve timestamp
« Reply #1 on: October 30, 2006, 04:30:24 pm »
Feel free to change it however you see fit. I just threw something together for the logs, then decided that it may be useful for other things so I moved it to util. I didn't know whether to use util or misc. I finally decided on util because it used _CurTime().

As far as the string.format thing goes, I have a habit of doing things like that the hard way, and not bothering to find a simple method unless I have a  need to do so. This is a bad habit I've picked up since everything I'de written previously has just been for myself.
I have not failed. I've just found 10,000 ways that won't work. - Thomas A. Edison
I reject your reality and substitute my own. - Adam Savage

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Improve timestamp
« Reply #2 on: November 02, 2006, 03:22:54 pm »
All above changes introduced in revision 136.
Experiencing God's grace one day at a time.

  • Print