Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ jobs:
run: yarn install --immutable

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

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

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

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

build-android:
runs-on: ubuntu-latest
Expand All @@ -59,7 +59,7 @@ jobs:
run: yarn install --immutable

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

- name: Cache Gradle
uses: actions/cache@v4
Expand All @@ -72,7 +72,7 @@ jobs:
${{ runner.os }}-gradle-

- name: Build Android example
working-directory: packages/native-date/example/android
working-directory: packages/example/android
run: ./gradlew assembleDebug --no-daemon

build-ios:
Expand All @@ -93,28 +93,28 @@ jobs:
run: yarn install --immutable

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

- name: Cache CocoaPods
uses: actions/cache@v4
with:
path: packages/native-date/example/ios/Pods
path: packages/example/ios/Pods
key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }}
restore-keys: |
${{ runner.os }}-pods-

- name: Install CocoaPods
working-directory: packages/native-date/example/ios
working-directory: packages/example/ios
run: pod install

- name: Build iOS example
working-directory: packages/native-date/example/ios
working-directory: packages/example/ios
run: |
xcodebuild \
-workspace NativeDateExample.xcworkspace \
-scheme NativeDateExample \
-sdk iphonesimulator \
-configuration Debug \
-destination 'platform=iOS Simulator,name=iPhone 15' \
-destination 'generic/platform=iOS Simulator' \
build \
CODE_SIGNING_ALLOWED=NO
27 changes: 20 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,25 @@ temp/
# Nitro generated (keep in git but ignore local changes)
# nitrogen/generated/

# Example app specific
packages/native-date/example/ios/Pods/
packages/native-date/example/ios/build/
packages/native-date/example/android/.gradle/
packages/native-date/example/android/build/
packages/native-date/example/android/app/build/

# Example apps (packages/example, packages/expo-example)
**/ios/Pods/
**/ios/build/
**/android/.gradle/
**/android/build/
**/android/app/build/
**/android/local.properties
**/.expo/
**/vendor/
**/.bundle/

# Expo generated
.expo/
*.jks
*.p8
*.p12
*.key
*.mobileprovision
*.orig.*
web-build/

.vscode/
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
66 changes: 66 additions & 0 deletions docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ All functions accept flexible date inputs and return timestamps (milliseconds si
type DateInput = number | string | Date;
```

::: warning v2.0 Breaking Changes
- `parse()` now uses **local time** for date-only strings (was UTC)
- Getter functions now return **local time** components (was UTC)

See [Release Notes](/RELEASE_NOTES_v2.0.0.md) for migration guide.
:::

## Parsing

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

---

## Setters

Immutable setters that return new timestamps:

| Function | Description |
|----------|-------------|
| `setYear(date, year)` | Set year |
| `setMonth(date, month)` | Set month (1-12) |
| `setDate(date, day)` | Set day of month |
| `setHours(date, hours)` | Set hours |
| `setMinutes(date, minutes)` | Set minutes |
| `setSeconds(date, seconds)` | Set seconds |
| `setMilliseconds(date, ms)` | Set milliseconds |

```typescript
setYear(date, 2026); // New timestamp with year 2026
setMonth(date, 3); // New timestamp with March
setDate(setMonth(date, 3), 15); // March 15th
```

::: tip
Setters handle edge cases automatically. Setting month to February when day is 31 will clamp to 28/29.
:::

---

## Arithmetic

| Function | Description |
Expand Down Expand Up @@ -194,6 +227,38 @@ isLeapYear(date); // false

---

## Timezone-Aware Predicates

Check dates in specific timezones. Essential for global apps where "today" depends on location.

| Function | Description |
|----------|-------------|
| `isTodayInTz(date, tz)` | Today in timezone? |
| `isTomorrowInTz(date, tz)` | Tomorrow in timezone? |
| `isYesterdayInTz(date, tz)` | Yesterday in timezone? |
| `isSameDayInTz(date1, date2, tz)` | Same day in timezone? |
| `isSameMonthInTz(date1, date2, tz)` | Same month in timezone? |
| `isSameYearInTz(date1, date2, tz)` | Same year in timezone? |
| `startOfDayInTz(date, tz)` | Midnight in timezone |
| `endOfDayInTz(date, tz)` | 23:59:59.999 in timezone |

```typescript
// Check if timestamp is "today" in Tokyo
isTodayInTz(date, 'Asia/Tokyo');

// Get midnight in New York (returns UTC timestamp)
startOfDayInTz(date, 'America/New_York');

// Compare two dates in London timezone
isSameDayInTz(date1, date2, 'Europe/London');
```

::: tip Use Case
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.
:::

---

## Boundaries

| Function | Description |
Expand Down Expand Up @@ -259,6 +324,7 @@ formatDuration(3600000); // "1h 0m 0s"
| `getTimezone()` | Device timezone ID |
| `getTimezoneOffset()` | Offset in minutes |
| `getTimezoneOffsetForTimestamp(date)` | Offset at date |
| `getOffsetInTimezone(date, tz)` | Offset for timezone at date |
| `toTimezone(date, tz)` | Convert to timezone |
| `toUTC(date)` | Convert to UTC |
| `getAvailableTimezones()` | All timezone IDs |
Expand Down
13 changes: 13 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ import { nativeDate } from '@bernagl/react-native-date/chain';
- **Zero-config locales** - Reads from OS, no plugins or imports
- **150+ locales** - Every locale supported by iOS/Android
- **Timezone support** - Full IANA timezone database from the OS
- **Timezone-aware predicates** - Check "is today in Tokyo?" etc.
- **Expo compatible** - Works with Expo Dev Client (SDK 54+)
- **Tiny footprint** - No locale bundles, minimal JS
- **Tree-shakeable** - Only bundle what you use
- **Type-safe** - Full TypeScript support
Expand All @@ -180,10 +182,21 @@ import { nativeDate } from '@bernagl/react-native-date/chain';
npm install @bernagl/react-native-date react-native-nitro-modules
```

### React Native CLI

```bash
cd ios && pod install
```

### Expo

Requires Expo Dev Client (not Expo Go):

```bash
npx expo prebuild
npx expo run:ios
```

No additional setup. No locale configuration. Just install and use.

---
Expand Down
Loading