Timer Format

Curtain supports various timer formats for flexibility in setting maintenance duration.

Supported Formats

# Time units
php artisan curtain:up --timer="30 minutes"
php artisan curtain:up --timer="2 hours"
php artisan curtain:up --timer="1 day"

# Combined formats
php artisan curtain:up --timer="1 hour 30 minutes"

Timer Parsing

// BaseCommand.php
protected function parseTimer(string $timer): string
{
    preg_match('/^(\d+)\s*(second|minute|hour|day|week)s?$/', $timer, $matches);
    
    $amount = (int) $matches[1];
    $unit = strtolower($matches[2]);

    return match($unit) {
        'second' => "PT{$amount}S",
        'minute' => "PT{$amount}M",
        'hour' => "PT{$amount}H",
        'day' => "P{$amount}D",
        'week' => "P" . ($amount * 7) . "D",
        default => throw new \InvalidArgumentException("Invalid time unit: {$unit}")
    };
}

Display Formats

// countdown.blade.php
formatTime(distance) {
    const hours = Math.floor(distance / (1000 * 60 * 60));
    const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
    const seconds = Math.floor((distance % (1000 * 60)) / 1000);

    return [hours, minutes, seconds].map(unit =>
        String(unit).padStart(2, '0')
    );
}

Features

  • Real-time Updates

    • Live countdown display

    • Automatic refresh

    • Smooth transitions

  • Format Validation

protected function validateTimer(?string $timer): bool
{
    if (!$timer) {
        return true;
    }

    return (bool) preg_match('/^\d+\s*(second|minute|hour|day|week)s?$/', $timer);
}
  • Cache Management

// CurtainService.php
protected function clearTimer(): void
{
    Cache::forget(self::CACHE_KEY);
}

protected function getTimer(): ?Carbon
{
    return Cache::get(self::CACHE_KEY);
}
  • User Experience

    • Clear time display

    • Intuitive format

    • Visual feedback

    • Error handling

Best Practices

  • Use reasonable durations

  • Provide clear end-time information

  • Handle timezone differences

  • Implement fallback mechanisms

Last updated