Quantcast Time format question - WoWInterface
Thread Tools Display Modes
08-27-19, 11:52 AM   #1
GreyFox777
A Cliff Giant
Join Date: Jan 2017
Posts: 74
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
  Reply With Quote
08-28-19, 12:50 AM   #2
lightspark
A Rage Talon Dragon Guard
 
lightspark's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 328
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.
__________________
  Reply With Quote
08-28-19, 10:47 AM   #3
GreyFox777
A Cliff Giant
Join Date: Jan 2017
Posts: 74
Originally Posted by lightspark View Post
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

Last edited by GreyFox777 : 08-28-19 at 03:35 PM.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Time format question

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off