Skip to content

Commit 84dc93d

Browse files
committed
deferred
1 parent 8a594ff commit 84dc93d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,25 @@ $duration = Duration::from(1200); // 1200 seconds
200200
$duration = Duration::from(500, Duration::UNIT_MINUTES);
201201
```
202202

203+
### Set or Parse Values deferred
204+
205+
Sometimes, you may want to configure the Measurement object first and then parse the value later.
206+
You can create an empty Measurement object and set value or parse value later, all Measurement objects
207+
are **immutable**, so you must assign the result to a new variable.
208+
209+
```php
210+
use Asika\BetterUnits\Duration;
211+
212+
$duration = new Duration()
213+
->withTropicalCalendar();
214+
215+
$duration = $duration->with(123, 'hours'); // Set value and units
216+
// OR
217+
$duration = $duration->withParse('123hours'/*, $scale, $roundingMode*/);
218+
// OR
219+
$duration = $duration->withFrom('123hours'/*, $scale, $roundingMode*/);
220+
```
221+
203222
## Unit Conversion
204223

205224
BetterUnits provides two ways to convert units: one retains the `Measurement` object after conversion, and the other

0 commit comments

Comments
 (0)