Skip to content

Commit b6f9d35

Browse files
authored
feat: release v2.0.0 with timezone-aware, predicates and setters (#2)
2 parents eda4394 + a6cb406 commit b6f9d35

96 files changed

Lines changed: 40378 additions & 1450 deletions

File tree

Some content is hidden

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

.github/workflows/ci.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ jobs:
2424
run: yarn install --immutable
2525

2626
- name: Lint
27-
run: yarn workspace @rn-packages/native-date lint
27+
run: yarn workspace @bernagl/react-native-date lint
2828

2929
- name: Type check
30-
run: yarn workspace @rn-packages/native-date typecheck
30+
run: yarn workspace @bernagl/react-native-date typecheck
3131

3232
- name: Run tests
33-
run: yarn workspace @rn-packages/native-date test
33+
run: yarn workspace @bernagl/react-native-date test
3434

3535
- name: Build
36-
run: yarn workspace @rn-packages/native-date prepare
36+
run: yarn workspace @bernagl/react-native-date prepare
3737

3838
build-android:
3939
runs-on: ubuntu-latest
@@ -59,7 +59,7 @@ jobs:
5959
run: yarn install --immutable
6060

6161
- name: Build library
62-
run: yarn workspace @rn-packages/native-date prepare
62+
run: yarn workspace @bernagl/react-native-date prepare
6363

6464
- name: Cache Gradle
6565
uses: actions/cache@v4
@@ -72,7 +72,7 @@ jobs:
7272
${{ runner.os }}-gradle-
7373
7474
- name: Build Android example
75-
working-directory: packages/native-date/example/android
75+
working-directory: packages/example/android
7676
run: ./gradlew assembleDebug --no-daemon
7777

7878
build-ios:
@@ -93,28 +93,28 @@ jobs:
9393
run: yarn install --immutable
9494

9595
- name: Build library
96-
run: yarn workspace @rn-packages/native-date prepare
96+
run: yarn workspace @bernagl/react-native-date prepare
9797

9898
- name: Cache CocoaPods
9999
uses: actions/cache@v4
100100
with:
101-
path: packages/native-date/example/ios/Pods
101+
path: packages/example/ios/Pods
102102
key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }}
103103
restore-keys: |
104104
${{ runner.os }}-pods-
105105
106106
- name: Install CocoaPods
107-
working-directory: packages/native-date/example/ios
107+
working-directory: packages/example/ios
108108
run: pod install
109109

110110
- name: Build iOS example
111-
working-directory: packages/native-date/example/ios
111+
working-directory: packages/example/ios
112112
run: |
113113
xcodebuild \
114114
-workspace NativeDateExample.xcworkspace \
115115
-scheme NativeDateExample \
116116
-sdk iphonesimulator \
117117
-configuration Debug \
118-
-destination 'platform=iOS Simulator,name=iPhone 15' \
118+
-destination 'generic/platform=iOS Simulator' \
119119
build \
120120
CODE_SIGNING_ALLOWED=NO

.gitignore

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,25 @@ temp/
122122
# Nitro generated (keep in git but ignore local changes)
123123
# nitrogen/generated/
124124

125-
# Example app specific
126-
packages/native-date/example/ios/Pods/
127-
packages/native-date/example/ios/build/
128-
packages/native-date/example/android/.gradle/
129-
packages/native-date/example/android/build/
130-
packages/native-date/example/android/app/build/
131-
125+
# Example apps (packages/example, packages/expo-example)
126+
**/ios/Pods/
127+
**/ios/build/
128+
**/android/.gradle/
129+
**/android/build/
130+
**/android/app/build/
131+
**/android/local.properties
132+
**/.expo/
133+
**/vendor/
134+
**/.bundle/
135+
136+
# Expo generated
137+
.expo/
138+
*.jks
139+
*.p8
140+
*.p12
141+
*.key
142+
*.mobileprovision
143+
*.orig.*
144+
web-build/
132145

133146
.vscode/

.yarnrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodeLinker: node-modules

docs/api-reference.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ All functions accept flexible date inputs and return timestamps (milliseconds si
66
type DateInput = number | string | Date;
77
```
88

9+
::: warning v2.0 Breaking Changes
10+
- `parse()` now uses **local time** for date-only strings (was UTC)
11+
- Getter functions now return **local time** components (was UTC)
12+
13+
See [Release Notes](/RELEASE_NOTES_v2.0.0.md) for migration guide.
14+
:::
15+
916
## Parsing
1017

1118
| Function | Description |
@@ -122,6 +129,32 @@ getComponents(date); // { year: 2025, month: 11, day: 30, ... }
122129

123130
---
124131

132+
## Setters
133+
134+
Immutable setters that return new timestamps:
135+
136+
| Function | Description |
137+
|----------|-------------|
138+
| `setYear(date, year)` | Set year |
139+
| `setMonth(date, month)` | Set month (1-12) |
140+
| `setDate(date, day)` | Set day of month |
141+
| `setHours(date, hours)` | Set hours |
142+
| `setMinutes(date, minutes)` | Set minutes |
143+
| `setSeconds(date, seconds)` | Set seconds |
144+
| `setMilliseconds(date, ms)` | Set milliseconds |
145+
146+
```typescript
147+
setYear(date, 2026); // New timestamp with year 2026
148+
setMonth(date, 3); // New timestamp with March
149+
setDate(setMonth(date, 3), 15); // March 15th
150+
```
151+
152+
::: tip
153+
Setters handle edge cases automatically. Setting month to February when day is 31 will clamp to 28/29.
154+
:::
155+
156+
---
157+
125158
## Arithmetic
126159

127160
| Function | Description |
@@ -194,6 +227,38 @@ isLeapYear(date); // false
194227

195228
---
196229

230+
## Timezone-Aware Predicates
231+
232+
Check dates in specific timezones. Essential for global apps where "today" depends on location.
233+
234+
| Function | Description |
235+
|----------|-------------|
236+
| `isTodayInTz(date, tz)` | Today in timezone? |
237+
| `isTomorrowInTz(date, tz)` | Tomorrow in timezone? |
238+
| `isYesterdayInTz(date, tz)` | Yesterday in timezone? |
239+
| `isSameDayInTz(date1, date2, tz)` | Same day in timezone? |
240+
| `isSameMonthInTz(date1, date2, tz)` | Same month in timezone? |
241+
| `isSameYearInTz(date1, date2, tz)` | Same year in timezone? |
242+
| `startOfDayInTz(date, tz)` | Midnight in timezone |
243+
| `endOfDayInTz(date, tz)` | 23:59:59.999 in timezone |
244+
245+
```typescript
246+
// Check if timestamp is "today" in Tokyo
247+
isTodayInTz(date, 'Asia/Tokyo');
248+
249+
// Get midnight in New York (returns UTC timestamp)
250+
startOfDayInTz(date, 'America/New_York');
251+
252+
// Compare two dates in London timezone
253+
isSameDayInTz(date1, date2, 'Europe/London');
254+
```
255+
256+
::: tip Use Case
257+
A global restaurant app needs to check if an order was placed "today" in the restaurant's local timezone, not the user's device timezone.
258+
:::
259+
260+
---
261+
197262
## Boundaries
198263

199264
| Function | Description |
@@ -259,6 +324,7 @@ formatDuration(3600000); // "1h 0m 0s"
259324
| `getTimezone()` | Device timezone ID |
260325
| `getTimezoneOffset()` | Offset in minutes |
261326
| `getTimezoneOffsetForTimestamp(date)` | Offset at date |
327+
| `getOffsetInTimezone(date, tz)` | Offset for timezone at date |
262328
| `toTimezone(date, tz)` | Convert to timezone |
263329
| `toUTC(date)` | Convert to UTC |
264330
| `getAvailableTimezones()` | All timezone IDs |

docs/index.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ import { nativeDate } from '@bernagl/react-native-date/chain';
157157
- **Zero-config locales** - Reads from OS, no plugins or imports
158158
- **150+ locales** - Every locale supported by iOS/Android
159159
- **Timezone support** - Full IANA timezone database from the OS
160+
- **Timezone-aware predicates** - Check "is today in Tokyo?" etc.
161+
- **Expo compatible** - Works with Expo Dev Client (SDK 54+)
160162
- **Tiny footprint** - No locale bundles, minimal JS
161163
- **Tree-shakeable** - Only bundle what you use
162164
- **Type-safe** - Full TypeScript support
@@ -180,10 +182,21 @@ import { nativeDate } from '@bernagl/react-native-date/chain';
180182
npm install @bernagl/react-native-date react-native-nitro-modules
181183
```
182184

185+
### React Native CLI
186+
183187
```bash
184188
cd ios && pod install
185189
```
186190

191+
### Expo
192+
193+
Requires Expo Dev Client (not Expo Go):
194+
195+
```bash
196+
npx expo prebuild
197+
npx expo run:ios
198+
```
199+
187200
No additional setup. No locale configuration. Just install and use.
188201

189202
---

0 commit comments

Comments
 (0)