Skip to content

Commit f304a69

Browse files
committed
docs: Update README with additional usage examples for country codes.
1 parent 3de17ae commit f304a69

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ of a country that groups the codes, its name, and all its IANA timezones.
4040
A two-letter code that represents a country name, recommended as the general purpose code.
4141

4242
```php
43+
use TinyBlocks\Country\Alpha2Code;
44+
4345
$alpha2Code = Alpha2Code::UNITED_STATES_OF_AMERICA;
4446

4547
$alpha2Code->name; # UNITED_STATES_OF_AMERICA
@@ -52,6 +54,8 @@ $alpha2Code->toAlpha3()->value; # USA
5254
A three-letter code that represents a country name, which is usually more closely related to the country name.
5355

5456
```php
57+
use TinyBlocks\Country\Alpha3Code;
58+
5559
$alpha3Code = Alpha3Code::UNITED_STATES_OF_AMERICA;
5660

5761
$alpha3Code->name; # UNITED_STATES_OF_AMERICA
@@ -74,6 +78,9 @@ Optionally, you can pass the name of the country. If no name is provided, the de
7478
country name.
7579

7680
```php
81+
use TinyBlocks\Country\Country;
82+
use TinyBlocks\Country\Alpha2Code;
83+
7784
$country = Country::from(alphaCode: Alpha2Code::UNITED_STATES_OF_AMERICA);
7885

7986
$country->name; # United States of America
@@ -82,6 +89,9 @@ $country->alpha3->value; # USA
8289
```
8390

8491
```php
92+
use TinyBlocks\Country\Country;
93+
use TinyBlocks\Country\Alpha3Code;
94+
8595
$country = Country::from(alphaCode: Alpha3Code::UNITED_STATES_OF_AMERICA);
8696

8797
$country->name; # United States of America
@@ -92,6 +102,9 @@ $country->alpha3->value; # USA
92102
If you want to specify a custom name:
93103

94104
```php
105+
use TinyBlocks\Country\Country;
106+
use TinyBlocks\Country\Alpha3Code;
107+
95108
$country = Country::from(alphaCode: Alpha3Code::UNITED_STATES_OF_AMERICA, name: 'United States');
96109

97110
$country->name; # United States
@@ -105,6 +118,8 @@ Alternatively, you can create a `Country` instance using the `fromString` method
105118
`Alpha-3` code as a string.
106119

107120
```php
121+
use TinyBlocks\Country\Country;
122+
108123
$country = Country::fromString(alphaCode: 'US');
109124

110125
$country->name; # United States of America
@@ -115,6 +130,8 @@ $country->alpha3->value; # USA
115130
You can also pass a custom country name:
116131

117132
```php
133+
use TinyBlocks\Country\Country;
134+
118135
$country = Country::fromString(alphaCode: 'USA', name: 'United States');
119136

120137
$country->name; # United States
@@ -128,6 +145,9 @@ Every `Country` includes an immutable `Timezones` collection, built from the IAN
128145
integration).
129146

130147
```php
148+
use TinyBlocks\Country\Country;
149+
use TinyBlocks\Country\Alpha2Code;
150+
131151
$country = Country::from(alphaCode: Alpha2Code::BRAZIL);
132152

133153
$country->timezones->count(); # 4
@@ -148,6 +168,9 @@ $country->timezones->all(); # [Timezone("America/Noronha"), Timezone("America/Be
148168
Returns the primary timezone (first in the IANA list). Falls back to `UTC` for territories without an assigned timezone:
149169

150170
```php
171+
use TinyBlocks\Country\Country;
172+
use TinyBlocks\Country\Alpha2Code;
173+
151174
$country = Country::from(alphaCode: Alpha2Code::JAPAN);
152175
$country->timezones->default(); # Timezone("Asia/Tokyo")
153176

@@ -160,6 +183,9 @@ $country->timezones->default(); # Timezone("UTC")
160183
Searches for a specific IANA identifier within the country's timezones:
161184

162185
```php
186+
use TinyBlocks\Country\Country;
187+
use TinyBlocks\Country\Alpha2Code;
188+
163189
$country = Country::from(alphaCode: Alpha2Code::UNITED_STATES_OF_AMERICA);
164190

165191
$country->timezones->findByIdentifier(iana: 'America/New_York'); # Timezone("America/New_York")
@@ -169,6 +195,9 @@ $country->timezones->findByIdentifier(iana: 'Asia/Tokyo'); # null
169195
#### Checking if a timezone belongs to the country
170196

171197
```php
198+
use TinyBlocks\Country\Country;
199+
use TinyBlocks\Country\Alpha2Code;
200+
172201
$country = Country::from(alphaCode: Alpha2Code::JAPAN);
173202

174203
$country->timezones->contains(iana: 'Asia/Tokyo'); # true
@@ -180,6 +209,8 @@ $country->timezones->contains(iana: 'America/New_York'); # false
180209
A `Timezone` is a Value Object representing a single valid IANA timezone identifier.
181210

182211
```php
212+
use TinyBlocks\Country\Timezone;
213+
183214
$timezone = Timezone::from(identifier: 'America/Sao_Paulo');
184215

185216
$timezone->value; # America/Sao_Paulo
@@ -189,6 +220,8 @@ $timezone->toString(); # America/Sao_Paulo
189220
Creating a UTC timezone:
190221

191222
```php
223+
use TinyBlocks\Country\Timezone;
224+
192225
$timezone = Timezone::utc();
193226

194227
$timezone->value; # UTC

0 commit comments

Comments
 (0)