Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tz in today transaction on coin page #16

Merged
merged 3 commits into from
Jan 4, 2025
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
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npm run typecheck && npm run test
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Version 0.1.9

### Fixed

- fix timezone for "today's transactions"

## Version 0.1.8

### Changed
Expand Down
97 changes: 67 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,6 @@ Want to try HabitTrove before installing? Visit the public [demo instance](https
- 🌙 Dark mode support (WIP)
- 📲 Progressive Web App (PWA) support (Planned)

## Getting Started

### Prerequisites

- Node.js 20 or later
- npm package manager

### Installation

1. Clone the repository:

```bash
git clone https://github.com/dohsimpson/habittrove.git
cd habittrove
```

2. Install dependencies:

```bash
npm install --force
```

3. Start the development server:

```bash
npm run dev
```

4. Open [http://localhost:3000](http://localhost:3000) with your browser to see the application.

## Usage

1. **Creating Habits**: Click the "Add Habit" button to create a new habit. Set a name, description, and coin reward.
Expand Down Expand Up @@ -109,6 +79,73 @@ npm run docker-run

The application data will be persisted in the `data` directory in both cases.

## Building the Project

To contribute to HabitTrove, you'll need to set up a development environment. Here's how to get started:

### Prerequisites

- Node.js 20 or later
- npm package manager
- Git (for version control)
- bun (for running tests)

### Setting Up the Development Environment

1. Clone the repository and navigate to the project directory:

```bash
git clone https://github.com/dohsimpson/habittrove.git
cd habittrove
```

2. Install project dependencies:

```bash
npm install --force
```

3. Set up the development environment:

```bash
npm run setup:dev
```

4. Start the development server:

```bash
npm run dev
```

5. Open [http://localhost:3000](http://localhost:3000) in your browser to access the development version.

### Running Tests

Before contributing, make sure to run the test suite:

```bash
npm test
```

### Building for Production

To build the project for production:

```bash
npm run build
```

This will create an optimized production build in the `.next` directory.

### Code Quality Tools

The project uses several tools to maintain code quality:

- ESLint for linting: `npm run lint`
- TypeScript type checking: `npm run type-check`

Run these commands regularly during development to catch issues early.

## Contributing

Contributions are welcome! We appreciate both:
Expand Down
2 changes: 1 addition & 1 deletion components/CoinsManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export default function CoinsManager() {
<div className="text-sm text-blue-800 dark:text-blue-100 mb-1">Today's Transactions</div>
<div className="text-2xl font-bold text-blue-900 dark:text-blue-50">
{transactions.filter(t =>
isSameDate(getNow({}), t2d({ timestamp: t.timestamp }))
isSameDate(getNow({ timezone: settings.system.timezone }), t2d({ timestamp: t.timestamp, timezone: settings.system.timezone }))
).length} 📊
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions lib/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('datetime utilities', () => {
const testDateTime = DateTime.fromISO(testTimestamp);

test('t2d should convert ISO timestamp to DateTime', () => {
const result = t2d({ timestamp: testTimestamp });
const result = t2d({ timestamp: testTimestamp, timezone: 'utc' });
// Normalize both timestamps to handle different UTC offset formats (Z vs +00:00)
expect(DateTime.fromISO(result.toISO()!).toMillis())
.toBe(DateTime.fromISO(testTimestamp).toMillis())
Expand All @@ -65,10 +65,10 @@ describe('datetime utilities', () => {
})

test('d2s should format DateTime for display', () => {
const result = d2s({ dateTime: testDateTime });
const result = d2s({ dateTime: testDateTime, timezone: 'utc' });
expect(result).toBeString()
const customFormat = d2s({ dateTime: testDateTime, format: 'yyyy-MM-dd' });

const customFormat = d2s({ dateTime: testDateTime, format: 'yyyy-MM-dd', timezone: 'utc' });
expect(customFormat).toBe('2024-01-01')
})

Expand Down
2 changes: 1 addition & 1 deletion lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function getNowInMilliseconds() {
}

// iso timestamp to datetime object, most for storage read
export function t2d({ timestamp, timezone }: { timestamp: string; timezone?: string }) {
export function t2d({ timestamp, timezone }: { timestamp: string; timezone: string }) {
return DateTime.fromISO(timestamp).setZone(timezone);
}

Expand Down
20 changes: 18 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"test": "bun test",
"typecheck": "tsc --noEmit",
"docker-build": "docker build -t habittrove .",
"docker-run": "docker run -p 3000:3000 -v $(pwd)/data:/app/data habittrove"
"docker-run": "docker run -p 3000:3000 -v $(pwd)/data:/app/data habittrove",
"prepare": "husky",
"setup:dev": "if ! command -v bun > /dev/null; then echo 'Installing bun...'; curl -fsSL https://bun.sh/install | bash; fi && npm install --force && npm run typecheck && npm run lint"
},
"dependencies": {
"@next/font": "^14.2.15",
Expand Down Expand Up @@ -52,6 +56,7 @@
"eslint": "^9",
"eslint-config-next": "15.1.3",
"eslint-plugin-unused-imports": "^4.1.4",
"husky": "^9.1.7",
"postcss": "^8",
"raw-loader": "^4.0.2",
"tailwindcss": "^3.4.1",
Expand Down
Loading