-
Notifications
You must be signed in to change notification settings - Fork 214
migrate Clock classes to API #1281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0845348
migrate Clock classes to API
brettmc d696772
review feedback
brettmc a6728ce
replace ClockFactory with Clock
brettmc e314f6f
remove time Util class
brettmc 9a665f5
Apply suggestions from code review
brettmc 477b845
Merge branch 'main' into clock-to-api
brettmc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OpenTelemetry\API\Common\Time; | ||
|
|
||
| final class ClockFactory implements ClockFactoryInterface | ||
| { | ||
| private static ?ClockInterface $default = null; | ||
|
|
||
| public static function create(): self | ||
| { | ||
| return new self(); | ||
| } | ||
|
|
||
| public function build(): ClockInterface | ||
| { | ||
| return new SystemClock(); | ||
| } | ||
|
|
||
| public static function getDefault(): ClockInterface | ||
| { | ||
| return self::$default ?? self::$default = self::create()->build(); | ||
| } | ||
|
|
||
| public static function setDefault(?ClockInterface $clock): void | ||
| { | ||
| self::$default = $clock; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OpenTelemetry\API\Common\Time; | ||
|
|
||
| interface ClockFactoryInterface | ||
| { | ||
| public static function create(): self; | ||
|
|
||
| public function build(): ClockInterface; | ||
|
|
||
| public static function getDefault(): ClockInterface; | ||
|
|
||
| public static function setDefault(?ClockInterface $clock): void; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OpenTelemetry\API\Common\Time; | ||
|
|
||
| interface ClockInterface | ||
| { | ||
| public const MILLIS_PER_SECOND = 1_000; | ||
| public const MICROS_PER_SECOND = 1_000_000; | ||
brettmc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public const NANOS_PER_SECOND = 1_000_000_000; | ||
| public const NANOS_PER_MILLISECOND = 1_000_000; | ||
| public const NANOS_PER_MICROSECOND = 1_000; | ||
|
|
||
| /** | ||
| * Returns the current epoch wall-clock timestamp in nanoseconds | ||
| */ | ||
| public function now(): int; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OpenTelemetry\API\Common\Time; | ||
|
|
||
| class Util | ||
brettmc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| /** @psalm-pure */ | ||
| public static function nanosToMicros(int $nanoseconds): int | ||
| { | ||
| return intdiv($nanoseconds, ClockInterface::NANOS_PER_MICROSECOND); | ||
| } | ||
|
|
||
| /** @psalm-pure */ | ||
| public static function nanosToMillis(int $nanoseconds): int | ||
| { | ||
| return intdiv($nanoseconds, ClockInterface::NANOS_PER_MILLISECOND); | ||
| } | ||
|
|
||
| /** @psalm-pure */ | ||
| public static function secondsToNanos(int $seconds): int | ||
| { | ||
| return $seconds * ClockInterface::NANOS_PER_SECOND; | ||
| } | ||
|
|
||
| /** @psalm-pure */ | ||
| public static function millisToNanos(int $milliSeconds): int | ||
| { | ||
| return $milliSeconds * ClockInterface::NANOS_PER_MILLISECOND; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.