# \[space-lua\] Time left in day with progress bar visual - version for v2

**URL:** <https://community.silverbullet.md/t/space-lua-time-left-in-day-with-progress-bar-visual-version-for-v2/3295>\
**Category:** Tricks & Techniques\
**Created:** [September 29, 2025, 8:18am UTC](https://community.silverbullet.md/t/space-lua-time-left-in-day-with-progress-bar-visual-version-for-v2/3295 "2025-09-29T08:18:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mr.Red](https://community.silverbullet.md/user_avatar/community.silverbullet.md/mr.red/32/821_2.png) [@Mr.Red](https://community.silverbullet.md/u/Mr.Red)\
**Post date:** [September 29, 2025, 8:18am UTC](https://community.silverbullet.md/t/space-lua-time-left-in-day-with-progress-bar-visual-version-for-v2/3295/1 "2025-09-29T08:18:35Z")

</div>

Continuing the discussion from [[Space-Script] Time left in day with progress bar visual](https://community.silverbullet.md/t/space-script-time-left-in-day-with-progress-bar-visual/1681):

This is a remake of the above `space-script` rewritten for v2 in `space-lua`

```auto
function timeLeftBar()
    local now = os.date("*t") -- get current time as a table
    local secondsPassed = now.hour * 3600 + now.min * 60 + now.sec
    local totalSeconds = 24 * 3600
    local secondsLeft = totalSeconds - secondsPassed
    local percentLeft = (secondsLeft / totalSeconds) * 100
    local percentPassed = 100 - percentLeft -- time gone

    -- Format time left as HH:MM
    local hoursLeft = math.floor(secondsLeft / 3600)
    local minutesLeft = math.floor((secondsLeft % 3600) / 60)
    local timeStr = string.format("%02d:%02d", hoursLeft, minutesLeft)

    -- Create progress bar (🟥 = time gone, 🟩 = time left)
    local barLength = 24
    local filledLength = math.floor((percentPassed / 100) * barLength)
    local bar = string.rep("🟥", filledLength) .. string.rep("🟩", barLength - filledLength)

    -- Combine everything
    local tlb = string.format("%s %s (%.1f%% left)", timeStr, bar, percentLeft)
    return tlb
end

```

Example how to use it in your page:

`🕑 Time Left: ${timeLeftBar()}`

This will look like this:

 ![image](https://community.silverbullet.md/uploads/default/original/2X/c/cead851c6cc8ec8159802051a47fc735cd22a315.png)

---

<div class="post-metadata">

**Author:** ![Mr.Red](https://community.silverbullet.md/user_avatar/community.silverbullet.md/mr.red/32/821_2.png) [@Mr.Red](https://community.silverbullet.md/u/Mr.Red)\
**Post date:** [September 29, 2025, 8:33am UTC](https://community.silverbullet.md/t/space-lua-time-left-in-day-with-progress-bar-visual-version-for-v2/3295/2 "2025-09-29T08:33:49Z")

</div>

And here if you want to track only your working hours (8:00 - 16:30 in the example below).  
Notice the inverted color logic compared to the above example ( 🟩 - time gone, 🟥 - time left):

```lua
function workTimeLeftBar()
    local now = os.date("*t") -- current time
    local currentSeconds = now.hour * 3600 + now.min * 60 + now.sec

    -- Define working window: 08:00 -> 16:30
    local startSeconds = 8 * 3600
    local endSeconds = 16 * 3600 + 30 * 60
    local totalSeconds = endSeconds - startSeconds

    -- Clamp currentSeconds to working window
    if currentSeconds < startSeconds then
        currentSeconds = startSeconds
    elseif currentSeconds > endSeconds then
        currentSeconds = endSeconds
    end

    -- Work out progress within window
    local secondsPassed = currentSeconds - startSeconds
    local secondsLeft = totalSeconds - secondsPassed
    local percentPassed = (secondsPassed / totalSeconds) * 100
    local percentLeft = 100 - percentPassed

    -- Format time left as HH:MM
    local hoursLeft = math.floor(secondsLeft / 3600)
    local minutesLeft = math.floor((secondsLeft % 3600) / 60)
    local timeStr = string.format("%02d:%02d", hoursLeft, minutesLeft)

    -- Progress bar (17 slots, one for each 30 minutes)
    local barLength = 17
    local filledLength = math.floor((percentPassed / 100) * barLength)
    local bar = string.rep("🟩", filledLength) .. string.rep("🟥", barLength - filledLength)

    return string.format("%s %s (%.1f%% left)", timeStr, bar, percentLeft)
end

```

use it in your page with:

`🕑 Worktime Left: ${workTimeLeftBar()}`

 ![image](https://community.silverbullet.md/uploads/default/original/2X/4/4ef3fdbfb289e99ef0d0c27fc79c571d3c36bdf0.png)
