Skip to content

Commit

Permalink
Merge pull request #24 from BJNSTNKVC/feature/#22
Browse files Browse the repository at this point in the history
  • Loading branch information
BJNSTNKVC authored Mar 18, 2024
2 parents d5d2970 + a3d662a commit f8c00b0
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3235,4 +3235,51 @@ Subtract weeks from the `Carbon` instance.
const carbon = Carbon.parse('2024-03-29 12:45:00').subWeeks(4);
console.log(carbon); // 2024-03-01 12:45:00
```
```
### Chaining Method Calls
You can chain multiple `set`, `add` or `sub` methods together to conveniently update multiple components of a `Carbon` instance in one
line.
#### Example
```javascript
const carbon = Carbon.parse('2024-03-01 12:45:00')
.setYear(2025)
.setMonth(5)
.setDay(15)
.setHour(18)
.setMinute(30)
.setSecond(45)
.setMillisecond(500);
console.log(carbon); // 2025-06-15 18:30:45.500 UTC (+02:00)
```
```javascript
const carbon = Carbon.parse('2024-03-01 12:45:00')
.addYears(2)
.addMonths(3)
.addDays(5)
.addHours(10)
.addMinutes(30)
.addSeconds(20)
.addMilliseconds(500);
console.log(carbon); // 2026-06-06 23:15:20.500 UTC (+02:00)
```
```javascript
const carbon = Carbon.parse('2024-03-01 12:45:00')
.subYears(2)
.subMonths(3)
.subDays(5)
.subHours(10)
.subMinutes(30)
.subSeconds(20)
.subMilliseconds(500);
console.log(carbon); // 2021-11-26 02:14:39.500 UTC (+01:00)
```

0 comments on commit f8c00b0

Please sign in to comment.