Skip to content

Commit eb5e305

Browse files
committed
Merge remote-tracking branch 'origin/3.next' into 4.x
2 parents 1bafb4c + 608bbc3 commit eb5e305

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+5282
-1457
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
pull_request:
1111
branches:
1212
- '*'
13+
workflow_dispatch:
1314

1415
permissions:
1516
contents: read

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
*.iml
33
.hhconfig
44
.phpunit.result.cache
5+
.phpcs.cache
56
vendor
67
composer.phar
78
composer.lock

Dockerfile

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,36 @@
1-
# Basic docker based environment
2-
# Necessary to trick dokku into building the documentation
3-
# using dockerfile instead of herokuish
4-
FROM php:8.1
1+
# ----------------------
2+
# 1. Build stage
3+
# ----------------------
4+
FROM node:22-alpine AS builder
55

6-
WORKDIR /code
6+
# Git is required because docs/package.json pulls a dependency from GitHub.
7+
RUN apk add --no-cache git openssh-client
78

8-
VOLUME ["/code"]
9+
WORKDIR /app/docs
910

10-
CMD [ '/bin/bash' ]
11+
# Copy dependency manifests first to preserve Docker layer caching.
12+
COPY docs/ ./
13+
RUN npm ci
14+
15+
# Increase max-old-space-size to avoid memory issues during build
16+
ENV NODE_OPTIONS="--max-old-space-size=8192"
17+
18+
# Build the site.
19+
RUN npm run docs:build
20+
21+
# ----------------------
22+
# 2. Runtime stage (nginx)
23+
# ----------------------
24+
FROM nginx:1.27-alpine AS runner
25+
26+
# Copy built files
27+
COPY --from=builder /app/docs/.vitepress/dist /usr/share/nginx/html
28+
29+
# Expose port
30+
EXPOSE 80
31+
32+
# Health check (optional)
33+
HEALTHCHECK CMD wget --quiet --tries=1 --spider http://localhost:80/ || exit 1
34+
35+
# Start nginx
36+
CMD ["nginx", "-g", "daemon off;"]

README.md

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,67 @@ echo $today->modify('+3 hours');
7777

7878
Like instances of `Chronos`, `ChronosDate` objects are also *immutable*.
7979

80+
# Time-only Values
81+
82+
When you need to work with just times (without dates), use `ChronosTime`:
83+
84+
```php
85+
use Cake\Chronos\ChronosTime;
86+
87+
$time = new ChronosTime('14:30:00');
88+
echo $time->format('g:i A'); // 2:30 PM
89+
90+
// Create from components
91+
$time = ChronosTime::create(14, 30, 0);
92+
93+
// Arithmetic
94+
$later = $time->addHours(2)->addMinutes(15);
95+
```
96+
97+
`ChronosTime` is useful for recurring schedules, business hours, or any scenario
98+
where the date is irrelevant.
99+
100+
# Testing with Chronos
101+
102+
Chronos provides `setTestNow()` to freeze time during testing:
103+
104+
```php
105+
use Cake\Chronos\Chronos;
106+
107+
// Freeze time for predictable tests
108+
Chronos::setTestNow('2024-01-15 10:00:00');
109+
110+
$now = Chronos::now(); // Always 2024-01-15 10:00:00
111+
112+
// Reset to real time
113+
Chronos::setTestNow(null);
114+
```
115+
116+
# PSR-20 Clock Interface
117+
118+
For dependency injection, use `ClockFactory` which implements PSR-20:
119+
120+
```php
121+
use Cake\Chronos\ClockFactory;
122+
123+
$clock = new ClockFactory('UTC');
124+
$now = $clock->now(); // Returns Chronos instance
125+
126+
// In your service
127+
class OrderService
128+
{
129+
public function __construct(private ClockInterface $clock) {}
130+
131+
public function createOrder(): Order
132+
{
133+
return new Order(createdAt: $this->clock->now());
134+
}
135+
}
136+
```
137+
80138
# Documentation
81139

82-
A more descriptive documentation can be found at [book.cakephp.org/chronos/3/en/](https://book.cakephp.org/chronos/3/en/).
140+
A more descriptive documentation can be found at [book.cakephp.org/chronos/3/](https://book.cakephp.org/chronos/3/).
83141

84142
# API Documentation
85143

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@
6161
"@cs-check",
6262
"@stan"
6363
],
64-
"cs-check": "phpcs --colors --parallel=16 -p",
65-
"cs-fix": "phpcbf --colors --parallel=16 -p",
64+
"cs-check": "phpcs",
65+
"cs-fix": "phpcbf",
6666
"phpstan": "tools/phpstan analyse",
6767
"stan": "@phpstan",
6868
"stan-baseline": "tools/phpstan --generate-baseline",

docs.Dockerfile

Lines changed: 0 additions & 26 deletions
This file was deleted.

docs/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
*/public/
3+
.vitepress/cache
4+
.vitepress/dist

docs/.vitepress/config.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import baseConfig from '@cakephp/docs-skeleton/config'
2+
import { createRequire } from 'module'
3+
4+
const require = createRequire(import.meta.url)
5+
const toc_en = require('./toc_en.json')
6+
const toc_fr = require('./toc_fr.json')
7+
const toc_ja = require('./toc_ja.json')
8+
const toc_pt = require('./toc_pt.json')
9+
10+
const versions = {
11+
text: '3.x',
12+
items: [
13+
{ text: '3.x (current)', link: 'https://book.cakephp.org/chronos/3/en/', target: '_self' },
14+
{ text: '2.x', link: 'https://book.cakephp.org/chronos/2/en/', target: '_self' },
15+
],
16+
}
17+
18+
export default {
19+
extends: baseConfig,
20+
srcDir: '.',
21+
title: 'Chronos',
22+
description: 'CakePHP Chronos Documentation',
23+
base: '/chronos/3/',
24+
rewrites: {
25+
'en/:slug*': ':slug*',
26+
},
27+
sitemap: {
28+
hostname: 'https://book.cakephp.org/chronos/3/',
29+
},
30+
themeConfig: {
31+
socialLinks: [
32+
{ icon: 'github', link: 'https://github.com/cakephp/chronos' },
33+
],
34+
editLink: {
35+
pattern: 'https://github.com/cakephp/chronos/edit/3.x/docs/:path',
36+
text: 'Edit this page on GitHub',
37+
},
38+
sidebar: toc_en,
39+
nav: [
40+
{ text: 'CakePHP', link: 'https://cakephp.org' },
41+
{ text: 'API', link: 'https://api.cakephp.org/chronos' },
42+
{ ...versions },
43+
],
44+
},
45+
locales: {
46+
root: {
47+
label: 'English',
48+
lang: 'en',
49+
themeConfig: {
50+
sidebar: toc_en,
51+
},
52+
},
53+
fr: {
54+
label: 'Français',
55+
lang: 'fr',
56+
themeConfig: {
57+
sidebar: toc_fr,
58+
},
59+
},
60+
ja: {
61+
label: '日本語',
62+
lang: 'ja',
63+
themeConfig: {
64+
sidebar: toc_ja,
65+
},
66+
},
67+
pt: {
68+
label: 'Português',
69+
lang: 'pt',
70+
themeConfig: {
71+
sidebar: toc_pt,
72+
},
73+
},
74+
},
75+
}

docs/.vitepress/theme/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from '@cakephp/docs-skeleton'

docs/.vitepress/toc_en.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"/": [
3+
{
4+
"text": "CakePHP Chronos",
5+
"collapsed": false,
6+
"items": [
7+
{ "text": "Introduction", "link": "/index" },
8+
{ "text": "3.x Migration Guide", "link": "/3-x-migration-guide" },
9+
{ "text": "API", "link": "https://api.cakephp.org/chronos" }
10+
]
11+
}
12+
]
13+
}

0 commit comments

Comments
 (0)