journey-cli 0.9.11

A CLI-based journal application with automatic timestamping, vault management, and Obsidian integration
Documentation
# Locale and Time Format Testing

## Overview

Comprehensive testing has been implemented for both US and Norwegian locales with support for both 12-hour and 24-hour time formats. The DateTimeHandler now intelligently handles different date and time formats based on the user's locale.

## Enhanced DateTimeHandler Features

### Locale-Aware Date Parsing

The DateTimeHandler now supports different date formats based on locale:

#### US Locale (`en-US`)
- **ISO Format**: `2025-10-24`
- **US Format**: `10/24/2025` (MM/DD/YYYY)
- **US with Dashes**: `10-24-2025` (MM-DD-YYYY)
- **US Long**: `October 24, 2025`
- **US Short**: `Oct 24, 2025`

#### Norwegian Locale (`no-NO`, `nb-NO`, `nn-NO`)
- **ISO Format**: `2025-10-24`
- **Norwegian Format**: `24.10.2025` (DD.MM.YYYY)
- **European Format**: `24/10/2025` (DD/MM/YYYY)
- **European with Dashes**: `24-10-2025` (DD-MM-YYYY)
- **Norwegian Long**: `24. oktober 2025`
- **Norwegian Short**: `24. okt 2025`

### Locale-Aware Time Parsing

Both locales support comprehensive time formats:

#### 24-Hour Format
- `14:30` - Basic 24-hour
- `14:30:45` - 24-hour with seconds

#### 12-Hour Format
- `2:30 PM` - Standard 12-hour
- `2:30:45 PM` - 12-hour with seconds
- `2:30PM` - Compact 12-hour
- `2:30:45PM` - Compact 12-hour with seconds

## Test Coverage

### US Locale Tests (6 tests)
- `test_us_locale_date_parsing()` - Tests various US date formats
- `test_us_locale_time_parsing_24h()` - Tests 24-hour time parsing
- `test_us_locale_time_parsing_12h()` - Tests 12-hour time parsing
- `test_us_locale_invalid_time()` - Tests invalid time handling
- `test_us_specific_date_formats()` - Tests US-specific date formats
- Cross-locale compatibility tests

### Norwegian Locale Tests (6 tests)
- `test_norwegian_locale_date_parsing()` - Tests various Norwegian date formats
- `test_norwegian_locale_time_parsing_24h()` - Tests 24-hour time parsing
- `test_norwegian_locale_time_parsing_12h()` - Tests 12-hour time parsing
- `test_norwegian_locale_invalid_time()` - Tests invalid time handling
- `test_norwegian_specific_date_formats()` - Tests Norwegian-specific date formats
- Cross-locale compatibility tests

### Cross-Locale Compatibility Tests (4 tests)
- `test_iso_date_cross_locale()` - ISO dates work across locales
- `test_24h_time_cross_locale()` - 24-hour times work across locales
- `test_12h_time_cross_locale()` - 12-hour times work across locales
- `test_cross_locale_date_ambiguity()` - Tests ambiguous date handling

### Locale-Specific Format Tests (2 tests)
- `test_us_specific_date_formats()` - US-specific formats
- `test_norwegian_specific_date_formats()` - Norwegian-specific formats

## Test Results

```
running 21 tests
test result: ok. 21 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
```

## Key Features Tested

### 1. Date Format Ambiguity Handling
```rust
// US interprets as MM/DD/YYYY (Jan 2)
"01/02/2025" → 2025-01-02

// Norwegian interprets as DD/MM/YYYY (Feb 1)  
"01/02/2025" → 2025-02-01
```

### 2. Time Format Flexibility
```rust
// All these work in both locales:
"14:30"        // 24-hour
"14:30:45"     // 24-hour with seconds
"2:30 PM"      // 12-hour
"2:30:45 PM"   // 12-hour with seconds
"2:30PM"       // Compact 12-hour
"2:30:45PM"    // Compact 12-hour with seconds
```

### 3. Invalid Input Handling
```rust
// These correctly fail:
"25:00"        // Invalid hour
"13:00 PM"     // Invalid combination
"25:30"        // Invalid hour
"14:70"        // Invalid minutes
"invalid"      // Completely invalid
```

### 4. Locale-Specific Date Formats
```rust
// US formats
"10/24/2025"   // MM/DD/YYYY
"10-24-2025"   // MM-DD-YYYY

// Norwegian formats  
"24.10.2025"   // DD.MM.YYYY
"24/10/2025"   // DD/MM/YYYY
"24-10-2025"   // DD-MM-YYYY
```

## Implementation Details

### DateTimeHandler Enhancements

1. **Locale Detection**: Uses `locale.starts_with()` to detect US (`en`) vs Norwegian (`no`, `nb`, `nn`) locales
2. **Format Arrays**: Uses `Vec<&str>` for flexible format lists per locale
3. **Error Messages**: Include locale information in error messages
4. **Fallback Support**: Default formats for unknown locales

### Test Organization

- **US Locale Section**: All US-specific tests grouped together
- **Norwegian Locale Section**: All Norwegian-specific tests grouped together  
- **Cross-Locale Section**: Compatibility and ambiguity tests
- **Legacy Section**: Backward compatibility tests

## Usage Examples

```rust
// US locale handler
let us_handler = DateTimeHandler::new("en-US".to_string());
us_handler.parse_date("10/24/2025").unwrap();  // MM/DD/YYYY
us_handler.parse_time("2:30 PM").unwrap();    // 12-hour

// Norwegian locale handler  
let no_handler = DateTimeHandler::new("no-NO".to_string());
no_handler.parse_date("24.10.2025").unwrap(); // DD.MM.YYYY
no_handler.parse_time("14:30").unwrap();      // 24-hour
```

## Benefits

1. **International Support**: Proper handling of different date/time conventions
2. **User-Friendly**: Accepts multiple formats per locale
3. **Robust**: Handles invalid input gracefully
4. **Flexible**: Supports both 12-hour and 24-hour time formats
5. **Compatible**: ISO formats work across all locales
6. **Tested**: Comprehensive test coverage ensures reliability

The enhanced DateTimeHandler now provides excellent international support while maintaining backward compatibility and robust error handling.