8000 Merge branch '6.4' into 7.0 · symfony/clock@9a01008 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
{"payload":{"commit":{"oid":"9a01008f53254ff9df53886ac28c6be9bbe33f0b","url":"/symfony/clock/commit/9a01008f53254ff9df53886ac28c6be9bbe33f0b","authoredDate":"2023-08-21T13:37:23.000+02:00","committedDate":"2023-08-21T13:37:23.000+02:00","shortMessage":null,"shortMessageMarkdown":"\u003cdiv\u003eMerge branch '6.4' into 7.0\u003c/div\u003e","shortMessageMarkdownLink":null,"bodyMessageHtml":"* 6.4:\n [FrameworkBundle] Deprecate not setting both `framework.session.save_path` and `framework.session.handler_id` at the same time\n [Translation] add \u003ca class=\"user-mention notranslate\" data-hovercard-type=\"user\" data-hovercard-url=\"/users/welcoMattic/hovercard\" data-octo-click=\"hovercard-link-click\" data-octo-dimensions=\"link_type:self\" href=\"https://github.com/welcoMattic\"\u003e@welcoMattic\u003c/a\u003e as codeowner\n [FrameworkBundle] Add `AbstractController::renderBlock()` and `renderBlockView()`\n [Clock] Add $modifier argument to now() helper","authors":[{"login":"nicolas-grekas","displayName":"Nicolas Grekas","avatarUrl":"https://avatars.githubusercontent.com/u/243674?v=4","path":"/nicolas-grekas","isGitHub":false}],"committerAttribution":false,"committer":{"login":"nicolas-grekas","displayName":"Nicolas Grekas","avatarUrl":"https://avatars.githubusercontent.com/u/243674?v=4","path":"/nicolas-grekas","isGitHub":false},"parents":["507dc9b4f886558e352431a73fd9266036d8af1f","a774a64bede0fde55c7971abeb4635309fc615da"],"globalRelayId":"C_kwDOHutE-doAKDlhMDEwMDhmNTMyNTRmZjlkZjUzODg2YWMyOGM2YmU5YmJlMzNmMGI","sha1":"507dc9b4f886558e352431a73fd9266036d8af1f","sha2":"9a01008f53254ff9df53886ac28c6be9bbe33f0b"},"currentUser":null,"repo":{"id":518735097,"defaultBranch":"7.3","name":"clock","ownerLogin":"symfony","currentUserCanPush":false,"isFork":false,"isEmpty":false,"createdAt":"2022-07-28T06:54:55.000Z","ownerAvatar":"https://avatars.githubusercontent.com/u/143937?v=4","public":true,"private":false,"isOrgOwned":true},"diffEntryData":[{"diffLines":[{"stylingDirective":null,"type":"HUNK","blobLineNumber":4,"text":"@@ -5,6 +5,7 @@ CHANGELOG","html":"@@ -5,6 +5,7 @@ CHANGELOG","displayNoNewLineWarning":false,"position":0,"left":4,"right":4},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":5,"text":" ---","html":" \u003cspan class=\"pl-ms\"\u003e---\u003c/span\u003e","displayNoNewLineWarning":false,"position":1,"left":5,"right":5},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":6,"text":" ","html":"\u003cbr\u003e","displayNoNewLineWarning":false,"position":2,"left":6,"right":6},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":7,"text":" * Throw `DateMalformedStringException`/`DateInvalidTimeZoneException` when appropriate","html":" \u003cspan class=\"pl-v\"\u003e*\u003c/span\u003e Throw \u003cspan class=\"pl-s\"\u003e`\u003c/span\u003e\u003cspan class=\"pl-c1\"\u003eDateMalformedStringException\u003c/span\u003e\u003cspan class=\"pl-s\"\u003e`\u003c/span\u003e/\u003cspan class=\"pl-s\"\u003e`\u003c/span\u003e\u003cspan class=\"pl-c1\"\u003eDateInvalidTimeZoneException\u003c/span\u003e\u003cspan class=\"pl-s\"\u003e`\u003c/span\u003e when appropriate","displayNoNewLineWarning":false,"position":3,"left":7,"right":7},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":8,"text":"+ * Add `$modifier` argument to the `now()` helper","html":"+ \u003cspan class=\"pl-v\"\u003e*\u003c/span\u003e Add \u003cspan class=\"pl-s\"\u003e`\u003c/span\u003e\u003cspan class=\"pl-c1\"\u003e$modifier\u003c/span\u003e\u003cspan class=\"pl-s\"\u003e`\u003c/span\u003e argument to the \u003cspan class=\"pl-s\"\u003e`\u003c/span\u003e\u003cspan class=\"pl-c1\"\u003enow()\u003c/span\u003e\u003cspan class=\"pl-s\"\u003e`\u003c/span\u003e helper","displayNoNewLineWarning":false,"position":4,"left":7,"right":8},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":9,"text":" ","html":"\u003cbr\u003e","displayNoNewLineWarning":false,"position":5,"left":8,"right":9},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":10,"text":" 6.3","html":" 6.3","displayNoNewLineWarning":false,"position":6,"left":9,"right":10},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":11,"text":" ---","html":" \u003cspan class=\"pl-ms\"\u003e---\u003c/span\u003e","displayNoNewLineWarning":false,"position":7,"left":10,"right":11}],"diffNumber":0,"diffSize":"0 Bytes","isBinary":false,"isTooBig":false,"collapsed":false,"isSubmodule":false,"lineCount":19,"linesChanged":1,"newTreeEntry":{"lineCount":19,"path":"CHANGELOG.md","mode":100644,"isGenerated":false},"oldTreeEntry":{"lineCount":0,"path":"CHANGELOG.md","mode":100644},"linesAdded":1,"linesDeleted":0,"path":"CHANGELOG.md","pathDigest":"06572a96a58dc510037d5efa622f9bec8519bc1beab13c9f251e97e657a9d4ed","status":"MODIFIED","truncatedReason":null,"oldOid":"507dc9b4f886558e352431a73fd9266036d8af1f","newOid":"9a01008f53254ff9df53886ac28c6be9bbe33f0b","copilotChatReference":null,"deletedSha":"507dc9b4f886558e352431a73fd9266036d8af1f","canToggleRichDiff":true,"defaultToRichDiff":false,"proseDifffHtml":null,"renderInfo":null,"dependencyDiffPath":null,"submodule":null},{"diffLines":[{"stylingDirective":null,"type":"HUNK","blobLineNumber":12,"text":"@@ -13,13 +13,29 @@","html":"@@ -13,13 +13,29 @@","displayNoNewLineWarning":false,"position":0,"left":12,"right":12},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":13,"text":" ","html":"\u003cbr\u003e","displayNoNewLineWarning":false,"position":1,"left":13,"right":13},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":14,"text":" if (!\\function_exists(now::class)) {","html":" \u003cspan class=pl-k\u003eif\u003c/span\u003e (!\u003cspan class=pl-en\u003e\\function_exists\u003c/span\u003e(now::class)) {","displayNoNewLineWarning":false,"position":2,"left":14,"right":14},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":15,"text":" /**","html":" \u003cspan class=pl-c\u003e/**\u003c/span\u003e","displayNoNewLineWarning":false,"position":3,"left":15,"right":15},{"stylingDirective":null,"type":"DELETION","blobLineNumber":16,"text":"- * Returns the current time as a DateTimeImmutable.","html":"-\u003cspan class=pl-c\u003e * Returns the current time as a DateTimeImmutable.\u003c/span\u003e","displayNoNewLineWarning":false,"position":4,"left":16,"right":15},{"stylingDirective":null,"type":"DELETION","blobLineNumber":17,"text":"- *","html":"-\u003cspan class=pl-c\u003e *\u003c/span\u003e","displayNoNewLineWarning":false,"position":5,"left":17,"right":15},{"stylingDirective":null,"type":"DELETION","blobLineNumber":18,"text":"- * Note that you should prefer injecting a ClockInterface or using","html":"-\u003cspan class=pl-c\u003e * Note that you should prefer injecting a ClockInterface or using\u003c/span\u003e","displayNoNewLineWarning":false,"position":6,"left":18,"right":15},{"stylingDirective":null,"type":"DELETION","blobLineNumber":19,"text":"- * ClockAwareTrait when possible instead of using this function.","html":"-\u003cspan class=pl-c\u003e * ClockAwareTrait when possible instead of using this function.\u003c/span\u003e","displayNoNewLineWarning":false,"position":7,"left":19,"right":15},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":16,"text":"+ * @throws \\DateMalformedStringException When the modifier is invalid","html":"+\u003cspan class=pl-c\u003e * @throws \\DateMalformedStringException When the modifier is invalid\u003c/span\u003e","displayNoNewLineWarning":false,"position":8,"left":19,"right":16},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":17,"text":" */","html":" \u003cspan class=pl-c\u003e */\u003c/span\u003e","displayNoNewLineWarning":false,"position":9,"left":20,"right":17},{"stylingDirective":null,"type":"DELETION","blobLineNumber":21,"text":"- function now(): \\DateTimeImmutable","html":"- \u003cspan class=\"pl-k\"\u003efunction\u003c/span\u003e \u003cspan class=\"pl-en\"\u003enow\u003c/span\u003e(): \u003cspan class=\"pl-smi\"\u003e\\\u003cspan class=\"pl-smi\"\u003eDateTimeImmutable\u003c/span\u003e\u003c/span\u003e","displayNoNewLineWarning":false,"position":10,"left":21,"right":17},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":18,"text":"+ function now(string $modifier = null): \\DateTimeImmutable","html":"+ \u003cspan class=\"pl-k\"\u003efunction\u003c/span\u003e \u003cspan class=\"pl-en\"\u003enow\u003c/span\u003e(\u003cspan class=\"pl-smi x x-first\"\u003estring\u003c/span\u003e\u003cspan class=\"x\"\u003e \u003c/span\u003e\u003cspan class=\"pl-s1\"\u003e\u003cspan class=\"pl-c1 x\"\u003e$\u003c/span\u003e\u003cspan class=\"x\"\u003emodifier\u003c/span\u003e\u003c/span\u003e\u003cspan class=\"x\"\u003e = \u003c/span\u003e\u003cspan class=\"pl-c1 x x-last\"\u003enull\u003c/span\u003e): \u003cspan class=\"pl-smi\"\u003e\\\u003cspan class=\"pl-smi\"\u003eDateTimeImmutable\u003c/span\u003e\u003c/span\u003e","displayNoNewLineWarning":false,"position":11,"left":21,"right":18},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":19,"text":" {","html":" {","displayNoNewLineWarning":false,"position":12,"left":22,"right":19},{"stylingDirective":null,"type":"DELETION","blobLineNumber":23,"text":"- return Clock::get()-\u003enow();","html":"- \u003cspan class=pl-k\u003ereturn\u003c/span\u003e Clock::\u003cspan class=pl-en\u003eget\u003c/span\u003e()-\u0026gt;\u003cspan class=pl-en\u003enow\u003c/span\u003e();","displayNoNewLineWarning":false,"position":13,"left":23,"right":19},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":20,"text":"+ if (null === $modifier || 'now' === $modifier) {","html":"+ \u003cspan class=pl-k\u003eif\u003c/span\u003e (\u003cspan class=pl-c1\u003enull\u003c/span\u003e === \u003cspan class=pl-s1\u003e\u003cspan class=pl-c1\u003e$\u003c/span\u003emodifier\u003c/span\u003e || \u003cspan class=pl-s\u003e\u0026#39;\u003cspan class=pl-s\u003enow\u003c/span\u003e\u0026#39;\u003c/span\u003e === \u003cspan class=pl-s1\u003e\u003cspan class=pl-c1\u003e$\u003c/span\u003emodifier\u003c/span\u003e) {","displayNoNewLineWarning":false,"position":14,"left":23,"right":20},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":21,"text":"+ return Clock::get()-\u003enow();","html":"+ \u003cspan class=pl-k\u003ereturn\u003c/span\u003e Clock::\u003cspan class=pl-en\u003eget\u003c/span\u003e()-\u0026gt;\u003cspan class=pl-en\u003enow\u003c/span\u003e();","displayNoNewLineWarning":false,"position":15,"left":23,"right":21},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":22,"text":"+ }","html":"+ }","displayNoNewLineWarning":false,"position":16,"left":23,"right":22},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":23,"text":"+","html":"+","displayNoNewLineWarning":false,"position":17,"left":23,"right":23},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":24,"text":"+ $now = Clock::get()-\u003enow();","html":"+ \u003cspan class=pl-s1\u003e\u003cspan class=pl-c1\u003e$\u003c/span\u003enow\u003c/span\u003e = Clock::\u003cspan class=pl-en\u003eget\u003c/span\u003e()-\u0026gt;\u003cspan class=pl-en\u003enow\u003c/span\u003e();","displayNoNewLineWarning":false,"position":18,"left":23,"right":24},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":25,"text":"+","html":"+","displayNoNewLineWarning":false,"position":19,"left":23,"right":25},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":26,"text":"+ if (\\PHP_VERSION_ID \u003c 80300) {","html":"+ \u003cspan class=pl-k\u003eif\u003c/span\u003e (\\\u003cspan class=pl-c1\u003ePHP_VERSION_ID\u003c/span\u003e \u0026lt; \u003cspan class=pl-c1\u003e80300\u003c/span\u003e) {","displayNoNewLineWarning":false,"position":20,"left":23,"right":26},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":27,"text":"+ try {","html":"+ \u003cspan class=pl-k\u003etry\u003c/span\u003e {","displayNoNewLineWarning":false,"position":21,"left":23,"right":27},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":28,"text":"+ $tz = (new \\DateTimeImmutable($modifier, $now-\u003egetTimezone()))-\u003egetTimezone();","html":"+ \u003cspan class=pl-s1\u003e\u003cspan class=pl-c1\u003e$\u003c/span\u003etz\u003c/span\u003e = (\u003cspan class=pl-k\u003enew\u003c/span\u003e \\\u003cspan class=pl-v\u003eDateTimeImmutable\u003c/span\u003e(\u003cspan class=pl-s1\u003e\u003cspan class=pl-c1\u003e$\u003c/span\u003emodifier\u003c/span\u003e, \u003cspan class=pl-s1\u003e\u003cspan class=pl-c1\u003e$\u003c/span\u003enow\u003c/span\u003e-\u0026gt;\u003cspan class=pl-en\u003egetTimezone\u003c/span\u003e()))-\u0026gt;\u003cspan class=pl-en\u003egetTimezone\u003c/span\u003e();","displayNoNewLineWarning":false,"position":22,"left":23,"right":28},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":29,"text":"+ } catch (\\Exception $e) {","html":"+ } \u003cspan class=pl-k\u003ecatch\u003c/span\u003e (\u003cspan class=pl-smi\u003e\\\u003cspan class=pl-smi\u003eException\u003c/span\u003e\u003c/span\u003e \u003cspan class=pl-s1\u003e\u003cspan class=pl-c1\u003e$\u003c/span\u003ee\u003c/span\u003e) {","displayNoNewLineWarning":false,"position":23,"left":23,"right":29},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":30,"text":"+ throw new \\DateMalformedStringException($e-\u003egetMessage(), $e-\u003egetCode(), $e);","html":"+ \u003cspan class=pl-k\u003ethrow\u003c/span\u003e \u003cspan class=pl-k\u003enew\u003c/span\u003e \\\u003cspan class=pl-v\u003eDateMalformedStringException\u003c/span\u003e(\u003cspan class=pl-s1\u003e\u003cspan class=pl-c1\u003e$\u003c/span\u003ee\u003c/span\u003e-\u0026gt;\u003cspan class=pl-en\u003egetMessage\u003c/span\u003e(), \u003cspan class=pl-s1\u003e\u003cspan class=pl-c1\u003e$\u003c/span\u003ee\u003c/span\u003e-\u0026gt;\u003cspan class=pl-en\u003egetCode\u003c/span\u003e(), \u003cspan class=pl-s1\u003e\u003cspan class=pl-c1\u003e$\u003c/span\u003ee\u003c/span\u003e);","displayNoNewLineWarning":false,"position":24,"left":23,"right":30},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":31,"text":"+ }","html":"+ }","displayNoNewLineWarning":false,"position":25,"left":23,"right":31},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":32,"text":"+ $now = $now-\u003esetTimezone($tz);","html":"+ \u003cspan class=pl-s1\u003e\u003cspan class=pl-c1\u003e$\u003c/span\u003enow\u003c/span\u003e = \u003cspan class=pl-s1\u003e\u003cspan class=pl-c1\u003e$\u003c/span\u003enow\u003c/span\u003e-\u0026gt;\u003cspan class=pl-en\u003esetTimezone\u003c/span\u003e(\u003cspan class=pl-s1\u003e\u003cspan class=pl-c1\u003e$\u003c/span\u003etz\u003c/span\u003e);","displayNoNewLineWarning":false,"position":26,"left":23,"right":32},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":33,"text":"+","html":"+","displayNoNewLineWarning":false,"position":27,"left":23,"right":33},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":34,"text":"+ return @$now-\u003emodify($modifier) ?: throw new \\DateMalformedStringException(error_get_last()['message'] ?? sprintf('Invalid date modifier \"%s\".', $modifier));","html":"+ \u003cspan class=pl-k\u003ereturn\u003c/span\u003e @\u003cspan class=pl-s1\u003e\u003cspan class=pl-c1\u003e$\u003c/span\u003enow\u003c/span\u003e-\u0026gt;\u003cspan class=pl-en\u003emodify\u003c/span\u003e(\u003cspan class=pl-s1\u003e\u003cspan class=pl-c1\u003e$\u003c/span\u003emodifier\u003c/span\u003e) ?: \u003cspan class=pl-k\u003ethrow\u003c/span\u003e \u003cspan class=pl-k\u003enew\u003c/span\u003e \\\u003cspan class=pl-v\u003eDateMalformedStringException\u003c/span\u003e(\u003cspan class=pl-en\u003eerror_get_last\u003c/span\u003e()[\u003cspan class=pl-s\u003e\u0026#39;\u003cspan class=pl-s\u003emessage\u003c/span\u003e\u0026#39;\u003c/span\u003e] ?? \u003cspan class=pl-en\u003esprintf\u003c/span\u003e(\u003cspan class=pl-s\u003e\u0026#39;\u003cspan class=pl-s\u003eInvalid date modifier \u0026quot;%s\u0026quot;.\u003c/span\u003e\u0026#39;\u003c/span\u003e, \u003cspan class=pl-s1\u003e\u003cspan class=pl-c1\u003e$\u003c/span\u003emodifier\u003c/span\u003e));","displayNoNewLineWarning":false,"position":28,"left":23,"right":34},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":35,"text":"+ }","html":"+ }","displayNoNewLineWarning":false,"position":29,"left":23,"right":35},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":36,"text":"+","html":"+","displayNoNewLineWarning":false,"position":30,"left":23,"right":36},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":37,"text":"+ $tz = (new \\DateTimeImmutable($modifier, $now-\u003egetTimezone()))-\u003egetTimezone();","html":"+ \u003cspan class=pl-s1\u003e\u003cspan class=pl-c1\u003e$\u003c/span\u003etz\u003c/span\u003e = (\u003cspan class=pl-k\u003enew\u003c/span\u003e \\\u003cspan class=pl-v\u003eDateTimeImmutable\u003c/span\u003e(\u003cspan class=pl-s1\u003e\u003cspan class=pl-c1\u003e$\u003c/span\u003emodifier\u003c/span\u003e, \u003cspan class=pl-s1\u003e\u003cspan class=pl-c1\u003e$\u003c/span\u003enow\u003c/span\u003e-\u0026gt;\u003cspan class=pl-en\u003egetTimezone\u003c/span\u003e()))-\u0026gt;\u003cspan class=pl-en\u003egetTimezone\u003c/span\u003e();","displayNoNewLineWarning":false,"position":31,"left":23,"right":37},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":38,"text":"+","html":"+","displayNoNewLineWarning":false,"position":32,"left":23,"right":38},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":39,"text":"+ return $now-\u003esetTimezone($tz)-\u003emodify($modifier);","html":"+ \u003cspan class=pl-k\u003ereturn\u003c/span\u003e \u003cspan class=pl-s1\u003e\u003cspan class=pl-c1\u003e$\u003c/span\u003enow\u003c/span\u003e-\u0026gt;\u003cspan class=pl-en\u003esetTimezone\u003c/span\u003e(\u003cspan class=pl-s1\u003e\u003cspan class=pl-c1\u003e$\u003c/span\u003etz\u003c/span\u003e)-\u0026gt;\u003cspan class=pl-en\u003emodify\u003c/span\u003e(\u003cspan class=pl-s1\u003e\u003cspan class=pl-c1\u003e$\u003c/span\u003emodifier\u003c/span\u003e);","displayNoNewLineWarning":false,"position":33,"left":23,"right":39},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":40,"text":" }","html":" }","displayNoNewLineWarning":false,"position":34,"left":24,"right":40},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":41,"text":" }","html":" }","displayNoNewLineWarning":false,"position":35,"left":25,"right":41}],"diffNumber":1,"diffSize":"0 Bytes","isBinary":false,"isTooBig":false,"collapsed":false,"isSubmodule":false,"lineCount":41,"linesChanged":28,"newTreeEntry":{"lineCount":41,"path":"Resources/now.php","mode":100644,"isGenerated":false},"oldTreeEntry":{"lineCount":0,"path":"Resources/now.php","mode":100644},"linesAdded":22,"linesDeleted":6,"path":"Resources/now.php","pathDigest":"e03b8437642c467ff6d14472bcf8633f991e87a0495a84e795c4e435be7160c8","status":"MODIFIED","truncatedReason":null,"oldOid":"507dc9b4f886558e352431a73fd9266036d8af1f","newOid":"9a01008f53254ff9df53886ac28c6be9bbe33f0b","copilotChatReference":null,"deletedSha":"507dc9b4f886558e352431a73fd9266036d8af1f","canToggleRichDiff":false,"defaultToRichDiff":false,"proseDifffHtml":null,"renderInfo":null,"dependencyDiffPath":null,"submodule":null},{"diffLines":[{"stylingDirective":null,"type":"HUNK","blobLineNumber":38,"text":"@@ -39,6 +39,19 @@ public function testNativeClock()","html":"@@ -39,6 +39,19 @@ public function testNativeClock()","displayNoNewLineWarning":false,"position":0,"left":38,"right":38},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":39,"text":" $this-\u003eassertInstanceOf(NativeClock::class, Clock::get());","html":" \u003cspan class=pl-s1\u003e\u003cspan class=pl-c1\u003e$\u003c/span\u003e\u003cspan class=pl-smi\u003ethis\u003c/span\u003e\u003c/span\u003e-\u0026gt;\u003cspan class=pl-en\u003eassertInstanceOf\u003c/span\u003e(NativeClock::class, Clock::\u003cspan class=pl-en\u003eget\u003c/span\u003e());","displayNoNewLineWarning":false,"position":1,"left":39,"right":39},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":40,"text":" }","html":" }","displayNoNewLineWarning":false,"position":2,"left":40,"right":40},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":41,"text":" ","html":"\u003cbr\u003e","displayNoNewLineWarning":false,"position":3,"left":41,"right":41},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":42,"text":"+ public function testNowModifier()","html":"+ \u003cspan class=pl-k\u003epublic\u003c/span\u003e \u003cspan class=pl-k\u003efunction\u003c/span\u003e \u003cspan class=pl-en\u003etestNowModifier\u003c/span\u003e()","displayNoNewLineWarning":false,"position":4,"left":41,"right":42},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":43,"text":"+ {","html":"+ {","displayNoNewLineWarning":false,"position":5,"left":41,"right":43},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":44,"text":"+ $this-\u003eassertSame('2023-08-14', now('2023-08-14')-\u003eformat('Y-m-d'));","html":"+ \u003cspan class=pl-s1\u003e\u003cspan class=pl-c1\u003e$\u003c/span\u003e\u003cspan class=pl-smi\u003ethis\u003c/span\u003e\u003c/span\u003e-\u0026gt;\u003cspan class=pl-en\u003eassertSame\u003c/span\u003e(\u003cspan class=pl-s\u003e\u0026#39;\u003cspan class=pl-s\u003e2023-08-14\u003c/span\u003e\u0026#39;\u003c/span\u003e, \u003cspan class=pl-en\u003enow\u003c/span\u003e(\u003cspan class=pl-s\u003e\u0026#39;\u003cspan class=pl-s\u003e2023-08-14\u003c/span\u003e\u0026#39;\u003c/span\u003e)-\u0026gt;\u003cspan class=pl-en\u003eformat\u003c/span\u003e(\u003cspan class=pl-s\u003e\u0026#39;\u003cspan class=pl-s\u003eY-m-d\u003c/span\u003e\u0026#39;\u003c/span\u003e));","displayNoNewLineWarning":false,"position":6,"left":41,"right":44},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":45,"text":"+ $this-\u003eassertSame('Europe/Paris', now('Europe/Paris')-\u003egetTimezone()-\u003egetName());","html":"+ \u003cspan class=pl-s1\u003e\u003cspan class=pl-c1\u003e$\u003c/span\u003e\u003cspan class=pl-smi\u003ethis\u003c/span\u003e\u003c/span\u003e-\u0026gt;\u003cspan class=pl-en\u003eassertSame\u003c/span\u003e(\u003cspan class=pl-s\u003e\u0026#39;\u003cspan class=pl-s\u003eEurope/Paris\u003c/span\u003e\u0026#39;\u003c/span\u003e, \u003cspan class=pl-en\u003enow\u003c/span\u003e(\u003cspan class=pl-s\u003e\u0026#39;\u003cspan class=pl-s\u003eEurope/Paris\u003c/span\u003e\u0026#39;\u003c/span\u003e)-\u0026gt;\u003cspan class=pl-en\u003egetTimezone\u003c/span\u003e()-\u0026gt;\u003cspan class=pl-en\u003egetName\u003c/span\u003e());","displayNoNewLineWarning":false,"position":7,"left":41,"right":45},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":46,"text":"+ $this-\u003eassertSame('UTC', now('UTC')-\u003egetTimezone()-\u003egetName());","html":"+ \u003cspan class=pl-s1\u003e\u003cspan class=pl-c1\u003e$\u003c/span\u003e\u003cspan class=pl-smi\u003ethis\u003c/span\u003e\u003c/span\u003e-\u0026gt;\u003cspan class=pl-en\u003eassertSame\u003c/span\u003e(\u003cspan class=pl-s\u003e\u0026#39;\u003cspan class=pl-s\u003eUTC\u003c/span\u003e\u0026#39;\u003c/span\u003e, \u003cspan class=pl-en\u003enow\u003c/span\u003e(\u003cspan class=pl-s\u003e\u0026#39;\u003cspan class=pl-s\u003eUTC\u003c/span\u003e\u0026#39;\u003c/span\u003e)-\u0026gt;\u003cspan class=pl-en\u003egetTimezone\u003c/span\u003e()-\u0026gt;\u003cspan class=pl-en\u003egetName\u003c/span\u003e());","displayNoNewLineWarning":false,"position":8,"left":41,"right":46},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":47,"text":"+ }","html":"+ }","displayNoNewLineWarning":false,"position":9,"left":41,"right":47},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":48,"text":"+","html":"+","displayNoNewLineWarning":false,"position":10,"left":41,"right":48},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":49,"text":"+ public function testInvalidNowModifier()","html":"+ \u003cspan class=pl-k\u003epublic\u003c/span\u003e \u003cspan class=pl-k\u003efunction\u003c/span\u003e \u003cspan class=pl-en\u003etestInvalidNowModifier\u003c/span\u003e()","displayNoNewLineWarning":false,"position":11,"left":41,"right":49},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":50,"text":"+ {","html":"+ {","displayNoNewLineWarning":false,"position":12,"left":41,"right":50},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":51,"text":"+ $this-\u003eexpectException(\\DateMalformedStringException::class);","html":"+ \u003cspan class=pl-s1\u003e\u003cspan class=pl-c1\u003e$\u003c/span\u003e\u003cspan class=pl-smi\u003ethis\u003c/span\u003e\u003c/span\u003e-\u0026gt;\u003cspan class=pl-en\u003eexpectException\u003c/span\u003e(\\DateMalformedStringException::class);","displayNoNewLineWarning":false,"position":13,"left":41,"right":51},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":52,"text":"+ now('invalid date');","html":"+ \u003cspan class=pl-en\u003enow\u003c/span\u003e(\u003cspan class=pl-s\u003e\u0026#39;\u003cspan class=pl-s\u003einvalid date\u003c/span\u003e\u0026#39;\u003c/span\u003e);","displayNoNewLineWarning":false,"position":14,"left":41,"right":52},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":53,"text":"+ }","html":"+ }","displayNoNewLineWarning":false,"position":15,"left":41,"right":53},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":54,"text":"+","html":"+","displayNoNewLineWarning":false,"position":16,"left":41,"right":54},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":55,"text":" public function testMockClockDisable()","html":" \u003cspan class=pl-k\u003epublic\u003c/span\u003e \u003cspan class=pl-k\u003efunction\u003c/span\u003e \u003cspan class=pl-en\u003etestMockClockDisable\u003c/span\u003e()","displayNoNewLineWarning":false,"position":17,"left":42,"right":55},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":56,"text":" {","html":" {","displayNoNewLineWarning":false,"position":18,"left":43,"right":56},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":57,"text":" $this-\u003eassertInstanceOf(NativeClock::class, Clock::get());","html":" \u003cspan class=pl-s1\u003e\u003cspan class=pl-c1\u003e$\u003c/span\u003e\u003cspan class=pl-smi\u003ethis\u003c/span\u003e\u003c/span\u003e-\u0026gt;\u003cspan class=pl-en\u003eassertInstanceOf\u003c/span\u003e(NativeClock::class, Clock::\u003cspan class=pl-en\u003eget\u003c/span\u003e());","displayNoNewLineWarning":false,"position":19,"left":44,"right":57},{"stylingDirective":null,"type":"HUNK","blobLineNumber":64,"text":"@@ -52,6 +65,7 @@ public function testMockClockFreeze()","html":"@@ -52,6 +65,7 @@ public function testMockClockFreeze()","displayNoNewLineWarning":false,"position":20,"left":51,"right":64},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":65,"text":" self::mockTime(new \\DateTimeImmutable('2021-12-19'));","html":" \u003cspan class=pl-smi\u003eself\u003c/span\u003e::\u003cspan class=pl-en\u003emockTime\u003c/span\u003e(\u003cspan class=pl-k\u003enew\u003c/span\u003e \\\u003cspan class=pl-v\u003eDateTimeImmutable\u003c/span\u003e(\u003cspan class=pl-s\u003e\u0026#39;\u003cspan class=pl-s\u003e2021-12-19\u003c/span\u003e\u0026#39;\u003c/span\u003e));","displayNoNewLineWarning":false,"position":21,"left":52,"right":65},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":66,"text":" ","html":"\u003cbr\u003e","displayNoNewLineWarning":false,"position":22,"left":53,"right":66},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":67,"text":" $this-\u003eassertSame('2021-12-19', now()-\u003eformat('Y-m-d'));","html":" \u003cspan class=pl-s1\u003e\u003cspan class=pl-c1\u003e$\u003c/span\u003e\u003cspan class=pl-smi\u003ethis\u003c/span\u003e\u003c/span\u003e-\u0026gt;\u003cspan class=pl-en\u003eassertSame\u003c/span\u003e(\u003cspan class=pl-s\u003e\u0026#39;\u003cspan class=pl-s\u003e2021-12-19\u003c/span\u003e\u0026#39;\u003c/span\u003e, \u003cspan class=pl-en\u003enow\u003c/span\u003e()-\u0026gt;\u003cspan class=pl-en\u003eformat\u003c/span\u003e(\u003cspan class=pl-s\u003e\u0026#39;\u003cspan class=pl-s\u003eY-m-d\u003c/span\u003e\u0026#39;\u003c/span\u003e));","displayNoNewLineWarning":false,"position":23,"left":54,"right":67},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":68,"text":"+ $this-\u003eassertSame('2021-12-20', now('+1 days')-\u003eformat('Y-m-d'));","html":"+ \u003cspan class=pl-s1\u003e\u003cspan class=pl-c1\u003e$\u003c/span\u003e\u003cspan class=pl-smi\u003ethis\u003c/span\u003e\u003c/span\u003e-\u0026gt;\u003cspan class=pl-en\u003eassertSame\u003c/span\u003e(\u003cspan class=pl-s\u003e\u0026#39;\u003cspan class=pl-s\u003e2021-12-20\u003c/span\u003e\u0026#39;\u003c/span\u003e, \u003cspan class=pl-en\u003enow\u003c/span\u003e(\u003cspan class=pl-s\u003e\u0026#39;\u003cspan class=pl-s\u003e+1 days\u003c/span\u003e\u0026#39;\u003c/span\u003e)-\u0026gt;\u003cspan class=pl-en\u003eformat\u003c/span\u003e(\u003cspan class=pl-s\u003e\u0026#39;\u003cspan class=pl-s\u003eY-m-d\u003c/span\u003e\u0026#39;\u003c/span\u003e));","displayNoNewLineWarning":false,"position":24,"left":54,"right":68},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":69,"text":" ","html":"\u003cbr\u003e","displayNoNewLineWarning":false,"position":25,"left":55,"right":69},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":70,"text":" self::mockTime('+1 days');","html":" \u003cspan class=pl-smi\u003eself\u003c/span\u003e::\u003cspan class=pl-en\u003emockTime\u003c/span\u003e(\u003cspan class=pl-s\u003e\u0026#39;\u003cspan class=pl-s\u003e+1 days\u003c/span\u003e\u0026#39;\u003c/span\u003e);","displayNoNewLineWarning":false,"position":26,"left":56,"right":70},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":71,"text":" $this-\u003eassertSame('2021-12-20', now()-\u003eformat('Y-m-d'));","html":" \u003cspan class=pl-s1\u003e\u003cspan class=pl-c1\u003e$\u003c/span\u003e\u003cspan class=pl-smi\u003ethis\u003c/span\u003e\u003c/span\u003e-\u0026gt;\u003cspan class=pl-en\u003eassertSame\u003c/span\u003e(\u003cspan class=pl-s\u003e\u0026#39;\u003cspan class=pl-s\u003e2021-12-20\u003c/span\u003e\u0026#39;\u003c/span\u003e, \u003cspan class=pl-en\u003enow\u003c/span\u003e()-\u0026gt;\u003cspan class=pl-en\u003eformat\u003c/span\u003e(\u003cspan class=pl-s\u003e\u0026#39;\u003cspan class=pl-s\u003eY-m-d\u003c/span\u003e\u0026#39;\u003c/span\u003e));","displayNoNewLineWarning":false,"position":27,"left":57,"right":71}],"diffNumber":2,"diffSize":"0 Bytes","isBinary":false,"isTooBig":false,"collapsed":false,"isSubmodule":false,"lineCount":96,"linesChanged":14,"newTreeEntry":{"lineCount":96,"path":"Tests/ClockTest.php","mode":100644,"isGenerated":false},"oldTreeEntry":{"lineCount":0,"path":"Tests/ClockTest.php","mode":100644},"linesAdded":14,"linesDeleted":0,"path":"Tests/ClockTest.php","pathDigest":"7b74de5cad27b9cf8f116af0ef9494541fb09ec9b72b8f9d87d38cdbc0f71c78","status":"MODIFIED","truncatedReason":null,"oldOid":"507dc9b4f886558e352431a73fd9266036d8af1f","newOid":"9a01008f53254ff9df53886ac28c6be9bbe33f0b","copilotChatReference":null,"deletedSha":"507dc9b4f886558e352431a73fd9266036d8af1f","canToggleRichDiff":false,"defaultToRichDiff":false,"proseDifffHtml":null,"renderInfo":null,"dependencyDiffPath":null,"submodule":null}],"splitViewPreference":"unified","ignoreWhitespace":false,"commentsPreference":"visible","diffLineSpacingPreference":"relaxed","useMonospaceFont":false,"pasteUrlLinkAsPlainText":false,"userNotices":[],"path":"/symfony/clock/commit/9a01008f53254ff9df53886ac28c6be9bbe33f0b","fileTreeExpanded":true,"headerInfo":{"additions":37,"deletions":6,"filesChanged":3,"filesChangedString":"3"},"moreDiffsToLoad":false,"asyncDiffLoadInfo":{"startIndex":3,"truncated":false,"byteCount":2608,"lineShownCount":72},"commentInfo":{"canComment":false,"locked":false,"canLock":false,"repoArchived":false},"csrf_tokens":{"/users/diffview?diff=split":{"post":"k0j2DhtQ4laolG4HP4ur_cA_p7b0k0xY2xAvaeIW2UyTpIXJoAA5brKX0GiNKNNlqHZFN-fT3DlwHjY18Kq5lA"},"/users/diffview?diff=unified":{"post":"NM41ZOFW16-CUTphYZCnE2MFwv73x3GQ-4awz6aDTF80IkajWgYMl5hShA7TM9-LC0wgf-SH4fFQiKmTtD8shw"},"/notifications/thread":{"post":"chFwM-w1VxAo8ExVBHybRm47iDhzaw5u8lGdHZN-tIuxFB4h-UOhaUIDyAWVnc 8000 ia4SfuNHnX17hCjY0AxDFmXQ"}}},"title":"Merge branch '6.4' into 7.0 · symfony/clock@9a01008","appPayload":{"helpUrl":"https://docs.github.com","findInDiffWorkerPath":"/assets-cdn/worker/find-in-diff-worker-6dcb06aa9fad.js","enabled_features":{"diff_ux_refresh_beta":false,"diff_inline_comments":true,"diff_ux_refresh_ssr_five":false,"diff_ux_refresh_ssr_ten":false}}}

Commit 9a01008

Browse files
Merge branch '6.4' into 7.0
* 6.4: [FrameworkBundle] Deprecate not setting both `framework.session.save_path` and `framework.session.handler_id` at the same time [Translation] add @welcoMattic as codeowner [FrameworkBundle] Add `AbstractController::renderBlock()` and `renderBlockView()` [Clock] Add $modifier argument to now() helper
2 parents 507dc9b + a774a64 commit 9a01008

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Throw `DateMalformedStringException`/`DateInvalidTimeZoneException` when appropriate
8+
* Add `$modifier` argument to the `now()` helper
89

910
6.3
1011
---

Resources/now.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,29 @@
1313

1414
if (!\function_exists(now::class)) {
1515
/**
16-
* Returns the current time as a DateTimeImmutable.
17-
*
18-
* Note that you should prefer injecting a ClockInterface or using
19-
* ClockAwareTrait when possible instead of using this function.
16+
* @throws \DateMalformedStringException When the modifier is invalid
2017
*/
21-
function now(): \DateTimeImmutable
18+
function now(string $modifier = null): \DateTimeImmutable
2219
{
23-
return Clock::get()->now();
20+
if (null === $modifier || 'now' === $modifier) {
21+
return Clock::get()->now();
22+
}
23+
24+
$now = Clock::get()->now();
25+
26+
if (\PHP_VERSION_ID < 80300) {
27+
try {
28+
$tz = (new \DateTimeImmutable($modifier, $now->getTimezone()))->getTimezone();
29+
} catch (\Exception $e) {
30+
throw new \DateMalformedStringException($e->getMessage(), $e->getCode(), $e);
31+
}
32+
$now = $now->setTimezone($tz);
33+
34+
return @$now->modify($modifier) ?: throw new \DateMalformedStringException(error_get_last()['message'] ?? sprintf('Invalid date modifier "%s".', $modifier));
35+
}
36+
37+
$tz = (new \DateTimeImmutable($modifier, $now->getTimezone()))->getTimezone();
38+
39+
return $now->setTimezone($tz)->modify($modifier);
2440
}
2541
}

Tests/ClockTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@ public function testNativeClock()
3939
$this->assertInstanceOf(NativeClock::class, Clock::get());
4040
}
4141

42+
public function testNowModifier()
43+
{
44+
$this->assertSame('2023-08-14', now('2023-08-14')->format('Y-m-d'));
45+
$this->assertSame('Europe/Paris', now('Europe/Paris')->getTimezone()->getName());
46+
$this->assertSame('UTC', now('UTC')->getTimezone()->getName());
47+
}
48+
49+
public function testInvalidNowModifier()
50+
{
51+
$this->expectException(\DateMalformedStringException::class);
52+
now('invalid date');
53+
}
54+
4255
public function testMockClockDisable()
4356
{
4457
$this->assertInstanceOf(NativeClock::class, Clock::get());
@@ -52,6 +65,7 @@ public function testMockClockFreeze()
5265
self::mockTime(new \DateTimeImmutable('2021-12-19'));
5366

5467
$this->assertSame('2021-12-19', now()->format('Y-m-d'));
68+
$this->assertSame('2021-12-20', now('+1 days')->format('Y-m-d'));
5569

5670
self::mockTime('+1 days');
5771
$this->assertSame('2021-12-20', now()->format('Y-m-d'));

0 commit comments

Comments
 (0)
0