WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   oUF (Otravi Unit Frames) (https://www.wowinterface.com/forums/forumdisplay.php?f=87)
-   -   Time format question (https://www.wowinterface.com/forums/showthread.php?t=57392)

GreyFox777 08-27-19 11:52 AM

Time format question
 
Hello guys, can some one show me how to edit this code, for showing the cast time in seconds/minutes/hours etc. ?

For example 1 | 10.0 to 1s | 10s

Lua Code:
  1. cast.OnCastbarUpdate = function(self, elapsed)
  2.     local currentTime = GetTime()
  3.     if self.casting or self.channeling then
  4.         local parent = self:GetParent()
  5.         local duration = self.casting and self.duration + elapsed or self.duration - elapsed
  6.         if (self.casting and duration >= self.max) or (self.channeling and duration <= 0) then
  7.             self.casting = nil
  8.             self.channeling = nil
  9.             return
  10.         end
  11.         if parent.unit == 'player' then
  12.             if self.delay ~= 0 then
  13.                 self.Time:SetFormattedText('%.1f | |cffff0000%.1f|r', duration, self.casting and self.max + self.delay or self.max - self.delay)
  14.             else
  15.                 self.Time:SetFormattedText('%.1f | %.1f', duration, self.max)
  16.                 if self.SafeZone and self.SafeZone.timeDiff then
  17.                     self.Lag:SetFormattedText("%d ms", self.SafeZone.timeDiff * 1000)
  18.                 end
  19.             end
  20.         else
  21.             self.Time:SetFormattedText('%.1f-%.1f', duration, self.casting and self.max + self.delay or self.max - self.delay)
  22.         end
  23.         self.duration = duration
  24.         self:SetValue(duration)
  25.         self.Spark:SetPoint('CENTER', self, 'LEFT', (duration / self.max) * self:GetWidth(), 0)
  26.     else
  27.         self.Spark:Hide()
  28.         local alpha = self:GetAlpha() - 0.02
  29.         if alpha > 0 then
  30.             self:SetAlpha(alpha)
  31.         else
  32.             self.fadeOut = nil
  33.             self:Hide()
  34.         end
  35.     end
  36. end

lightspark 08-28-19 12:50 AM

duration is a float, it gives you seconds and milliseconds. If you want to show minutes, hours, days, etc., you'll need to do some maths. For example, math.floor(duration / 60) will give you minutes, math.floor(duration / 3600) will result in hours, and so on.

GreyFox777 08-28-19 10:47 AM

Quote:

Originally Posted by lightspark (Post 333400)
duration is a float, it gives you seconds and milliseconds. If you want to show minutes, hours, days, etc., you'll need to do some maths. For example, math.floor(duration / 60) will give you minutes, math.floor(duration / 3600) will result in hours, and so on.


Thx for your response! Have already did it :)


All times are GMT -6. The time now is 03:11 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI