Skip to content

Commit

Permalink
Discovery: STUB: Add ExpireTimestampConverter.
Browse files Browse the repository at this point in the history
  • Loading branch information
donquixote committed Jan 17, 2025
1 parent 1b49e5d commit ceea53e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions collabora_online.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ services:
logger.channel.collabora_online:
parent: logger.channel_base
arguments: ['cool']
Drupal\collabora_online\ExpireTimestampConverter: {}
Drupal\collabora_online\Discovery\CollaboraDiscoveryFetcherInterface:
class: Drupal\collabora_online\Discovery\CollaboraDiscoveryFetcher
Drupal\collabora_online\Discovery\CachingDiscoveryFetcher:
Expand Down
33 changes: 33 additions & 0 deletions src/Time/ExpireTimestampConverter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Drupal\collabora_online\Time;

use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Cache\Cache;

/**
* Service to convert between expire timestamp and cache max-age value.
*/
class ExpireTimestampConverter {

public function __construct(
protected readonly TimeInterface $time,
) {}

public function getExpireTimestamp(int $max_age): int {
if ($max_age === Cache::PERMANENT) {
return Cache::PERMANENT;
}
return $max_age + $this->time->getRequestTime();
}

public function getMaxAge(int $expire): int {
if ($expire === Cache::PERMANENT) {
return Cache::PERMANENT;
}
return $expire - $this->time->getRequestTime();
}

}

0 comments on commit ceea53e

Please sign in to comment.