Add clock mode that displays current system time (#2)#6
Merged
Conversation
- Add new --clock/-k option to display current system time - Shows time in clean HH:MM:SS format, updating every second - Implemented using system time for accuracy (handles DST, NTP sync) - Integrated with existing conflict detection and help system - Updated README and manual page with clock mode documentation - Updated ChangeLog with feature details - Bump version to 0.5-2 - Fixed trailing whitespace in source files Resolves #2
Keep clock mode as pure feature implementation. Version bump will be handled in separate PR after feature merge.
FEATURE: - Added --milliseconds (-m) flag to show milliseconds in clock mode - Clock mode without -m: shows HH:MM:SS (e.g., 10:21:00) - Clock mode with -m: shows HH:MM:SS.mmm (e.g., 10:21:09.405) - Preserves existing millisecond display for timer/countdown/stopwatch modes - Synced with master to get build system fixes IMPLEMENTATION: - Added show_milliseconds flag to Config structure - Modified timer_print() to conditionally format clock output - Fixed GOption variable declarations (gboolean, not gboolean*) - All tests pass, backward compatibility maintained DOCUMENTATION: - Updated README.md with usage examples - Enhanced manual page (utimer.1) with detailed option description - Added comprehensive ChangeLog entry TESTING VERIFIED: ✓ Clock mode: -k shows HH:MM:SS, -k -m shows HH:MM:SS.mmm ✓ Other modes: -m flag has no effect (already show milliseconds) ✓ Conflict detection works for incompatible mode combinations ✓ All utility options (--help, --version, --limits) work correctly ✓ Full test suite passes ✓ Out-of-tree build (build.sh) works correctly
…ck mode clarity - Added enhanced development workflow and build system documentation - Added detailed development section with minimal source approach explanation - Included release tarball creation and proper test instructions - Clarified clock mode description: 'clock (with optional milliseconds)' - Maintained scripting support mention as key differentiating feature - Enhanced documentation for contributors and maintainers
- Removed unused 'guint total_sec = sec;' variable to eliminate compiler warning - Function logic unchanged, still works correctly for clock display - Clean compilation without warnings
- Replaced timer_sec_msec_to_clock_string() and timer_sec_msec_to_clock_string_with_ms() - With single timer_sec_msec_to_clock_string(sec, msec, show_milliseconds) function - Eliminates code duplication in time calculation logic - Cleaner API with conditional formatting based on boolean parameter - More maintainable - changes only need one location - Consistent with existing conditional logic patterns
- Changed help text from '(--clock)' to '(only affects --clock)' - Makes it crystal clear that -m flag only works with clock mode - Eliminates potential user confusion about option scope - Keeps CLI help perfectly in sync with man page documentation
- Add test for basic clock format validation (--clock help output) - Add test for milliseconds format validation (--clock --milliseconds help output) - Add test for conflict detection (--clock with timer mode) - All tests use help output validation for reliable cross-platform testing - Tests integrated with autotools build system via 'make check'
- Replace raw wait status check with g_spawn_check_wait_status() - Ensures accurate cross-platform exit code validation - Eliminates deprecation warning from g_spawn_check_exit_status() - Test still correctly validates that conflicting flags exit with error
- Add test_clock_formatter_values() to test timer_sec_msec_to_clock_string() directly - Test edge cases: 00:00:00, 23:59:59, 24h+ wraparound, milliseconds formatting - Fast deterministic tests without process spawning - Validates formatter logic independently of CLI integration - Now includes both CLI smoke tests and direct unit tests for comprehensive coverage
- Rename timer_sec_msec_to_clock_string() to timer_clock_string_from_sec_msec() - New name better reflects that it creates a clock string from seconds/milliseconds - Clarifies that the function can return both HH:MM:SS and HH:MM:SS.mmm formats - Updates function documentation to reflect optional millisecond formatting - More intuitive API naming for future maintainers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add Clock Mode Feature
🎯 Overview
This PR implements a new clock mode for µTimer that displays the current system time in real-time. The clock mode provides accurate timekeeping by reading the system time every second and displaying it in a clean, readable format.
📋 Changes Summary
🕒 New Clock Mode Feature
--clock(long) and-k(short) command-line optionsHH:MM:SSformat (e.g.,14:23:45)🔧 Technical Implementation
TIMER_MODE_CLOCKto existing timer frameworkclock_get_diff(): Reads current system time using GDateTimeclock_new_timer(): Creates clock timer instancetimer_sec_msec_to_clock_string(): Formats time for clean display📚 Documentation Updates
utimer.1): Added clock mode documentation with usage examples🔧 Code Quality Improvements
🚀 Usage Examples
Basic clock mode:
# Show current time (updates every second) utimer --clock utimer -kExample output:
Integration with existing features:
🧪 Testing
-k) and long (--clock) options work📊 Impact
New Capabilities
Backward Compatibility
Performance
🔗 Related Issues
Resolves #2 - Clock mode that shows current time
📝 Notes for Maintainers