Skip to content

Conversation

@jackspirou
Copy link
Member

πŸš€ Major Enhancements

This PR significantly enhances the UTC package with new features, improved safety, and better developer experience.

✨ New Features

Flexible Parsing & Encoding:

  • πŸ”„ Flexible JSON/text parsing supports RFC3339, RFC3339Nano, date-only ("2024-01-02"), and datetime ("2024-01-02 15:04:05")
  • πŸ“ Implements encoding.TextMarshaler/TextUnmarshaler for broader codec support
  • οΏ½οΏ½ Enhanced Scan() method with []byte support and flexible format parsing

Unix Timestamp Utilities:

  • ⏰ FromUnix(sec) and FromUnixMilli(ms) constructors
  • πŸ“Š Unix() and UnixMilli() methods for easy conversion
  • πŸ• StartOfDay() and EndOfDay() for day boundary calculations

Timezone Helpers:

  • 🌍 In(name string) for converting to any timezone by name
  • πŸ“ InLocation(loc *time.Location) for pre-loaded locations
  • πŸ”„ Generic timezone conversion with error handling

Debug Mode:

  • πŸ› Conditional debug logging (build with -tags debug)
  • πŸ“‹ Logs nil receiver method calls to help identify bugs during development
  • πŸ”§ No performance impact in production builds

πŸ›‘οΈ Safety Improvements

Nil-Safe Operations:

  • ❌ Eliminates panics in favor of graceful error handling
  • πŸ”€ String() returns "<nil>" instead of panicking (follows stdlib conventions)
  • πŸ’Ύ Value() returns proper errors for database operations
  • πŸ›Ÿ All nil receivers handled safely across the API

πŸ“ˆ Code Quality

Improved Naming:

  • 🏷️ Removed redundant "UTC" suffixes (e.g., StartOfDayUTC β†’ StartOfDay)
  • πŸ“– Follows Go naming conventions for clarity
  • πŸ”§ Simplified internal function names

Comprehensive Testing:

  • βœ… 94.3% test coverage (improved from 79%)
  • πŸ§ͺ All new functions have 100% coverage
  • πŸ› Debug mode functionality fully tested
  • πŸ” Edge cases and error paths covered

Modern Go:

  • πŸ†• Updated to Go 1.18+ (uses any type)
  • πŸ“š Enhanced documentation with design rationale
  • πŸ—οΈ Build tags for debug/production modes

πŸ“– Documentation

  • πŸ“‹ Updated README with all new features
  • πŸ› Debug mode usage examples
  • πŸ’‘ Design decision explanations
  • πŸ”§ Installation requirements documented

πŸ”„ Backward Compatibility

  • βœ… 100% backward compatible - no breaking changes
  • πŸ”„ All existing APIs work exactly as before
  • πŸ§ͺ All original tests still pass
  • πŸ“¦ Drop-in replacement for existing usage

πŸ§ͺ Testing

# Run tests
go test ./...

# Run with debug mode
go test -tags debug ./...

# Check coverage
go test -cover ./...

This enhancement makes the UTC package significantly more powerful while maintaining full compatibility and improving safety for production use.

Major enhancements:
- Add flexible JSON/text parsing (RFC3339, RFC3339Nano, date-only, datetime)
- Implement encoding.TextMarshaler/TextUnmarshaler interfaces
- Add Unix timestamp helpers: FromUnix(), FromUnixMilli(), Unix(), UnixMilli()
- Add day boundary utilities: StartOfDay(), EndOfDay()
- Add generic timezone helpers: In(name), InLocation(loc)
- Enhanced Scan() with []byte support and flexible parsing
- Add debug mode with conditional logging (build with -tags debug)

Safety improvements:
- Replace panics with graceful error handling for nil receivers
- String() returns "<nil>" instead of panicking
- Value() returns error instead of panicking
- Comprehensive nil-safe operations

Code quality:
- Improve function naming (remove redundant UTC suffix)
- Add extensive test coverage (94.3%)
- Add debug mode tests
- Update to Go 1.18 (uses 'any' type)
- Follow Go naming conventions

Documentation:
- Update README with new features and debug mode usage
- Add comprehensive package documentation
- Document design decisions for nil handling
- Add installation requirements
@codecov-commenter
Copy link

Welcome to Codecov πŸŽ‰

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment

Thanks for integrating Codecov - We've got you covered β˜‚οΈ

@jackspirou jackspirou merged commit eca8f2c into master Aug 8, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants