Skip to content

Conversation

@Acidicts
Copy link
Contributor

@Acidicts Acidicts commented Jan 3, 2026

I think it this bit

/app/helper/application_helper.rb

def format_seconds(seconds, include_days: false)
    return "0s" if seconds.nil? || seconds <= 0

    days = seconds / 86400
    hours = (seconds % 86400) / 3600
    minutes = (seconds % 3600) / 60
    secs = seconds % 60

    parts = []
    parts << "#{days}d" if include_days && days > 0
    parts << "#{hours}h" if hours > 0 || (include_days && days > 0)
    parts << "#{minutes}m" if minutes > 0 || parts.any?
    parts << "#{secs}s" if parts.empty?

    parts.join(" ")
  end

I'm presuming include_days is false which means hours is put only until it reaches 24hr
parts << "#{hours}h" if hours > 0 || (include_days && days > 0) where it should be parts << "#{hours}h" if hours > 0 || (! include_days && days > 0)

My Version is:

def format_seconds(seconds, include_days = false)
    return "0s" if seconds.nil? || seconds <= 0

    days = seconds / 86400
    hours = include_days ? (seconds % 86400) / 3600 : seconds / 3600
    
    minutes = (seconds % 3600) / 60
    secs = seconds % 60

    parts = []
    parts << "#{days}d" if include_days && days > 0
    parts << "#{hours}h" if hours > 0 || (!include_days && days > 0)
    parts << "#{minutes}m" if minutes > 0 || parts.any?
    
    parts << "#{secs}s" if parts.empty?

    parts.join(" ")
end

Once reaching 24hrs of time or 86400 seconds it would not display those 24hrs. My fix makes it show hours above 24 if there include_days is false and if it true it simplifies it into days aswell, and following the current formatting it hides the hours, if zero.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug in the format_seconds helper method where hours would not accumulate beyond 24 when include_days is set to false. Previously, hours would max out at 23h even for durations exceeding 24 hours when days were not being displayed.

Key Changes:

  • Modified hours calculation to accumulate all hours when include_days is false, instead of resetting after 24 hours
  • Updated the hours display condition to show hours when there are accumulated days but include_days is false

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

parts << "#{hours}h" if hours > 0 || (include_days && days > 0)
parts << "#{hours}h" if hours > 0 || (!include_days && days > 0)
parts << "#{minutes}m" if minutes > 0 || parts.any?

Copy link

Copilot AI Jan 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected on this line. This should be removed to maintain consistent code style.

Copilot uses AI. Check for mistakes.
end

def format_seconds(seconds, include_days: false)
def format_seconds(seconds, include_days = false)
Copy link

Copilot AI Jan 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing from keyword argument syntax (include_days:) to positional argument syntax (include_days =) is a breaking API change. Existing calls using include_days: true will fail. Looking at the codebase, there are multiple calls in app/views/admin/fulfillment_dashboard/index.html.erb using the keyword argument syntax (include_days: true) that will break with this change.

Suggested change
def format_seconds(seconds, include_days = false)
def format_seconds(seconds, include_days = false, **options)
include_days = options.fetch(:include_days, include_days)

Copilot uses AI. Check for mistakes.
days = seconds / 86400
hours = (seconds % 86400) / 3600
hours = include_days ? (seconds % 86400) / 3600 : seconds / 3600

Copy link

Copilot AI Jan 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected on this line. This should be removed to maintain consistent code style.

Suggested change

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant