2 unstable releases
0.2.0 | Nov 8, 2021 |
---|---|
0.1.0 | Nov 4, 2021 |
#1790 in Rust patterns
10KB
216 lines
morseclock - Yet another not-so-intuitive clock
This is a WIP. Use at your own discretion.
lib.rs
:
morseclock - Yet another not-so-intuitive clock
morseclock allows you to generate a clock visualization inspired by this hackaday post
Usage example
use morseclock::{Clock, Format, MorseExt};
// Hour must be in the range [0, 23)
let hour = 16.try_into().unwrap();
// Minute must be in the range [0, 59)
let minute = 47.try_into().unwrap();
let clock = Clock::new(hour, minute, Format::Hour12);
let time: String = clock
.into_iter()
.morse()
.collect();
assert_eq!(time, "--.=----")
How to read the "morsecode"
The mapping generated by the MorseExt
iterator extension trait can be interpreted as follows
The string "--.=----"
represents the time 4:47.
The character '='
separates the hour-hand from the minute-hand.
On the hour-hand a single '-'
stands for a increment of of 3 hours (a quarter rotation of the hand), starting at the 0 o'clock position.
A single '.'
stands for an increment of 1 hour.
On the minute-hand, a single '-'
stands for a increment of 15 minutes (a quarter rotation of the hand), starting at the 0 o'clock position.
A single '.'
stands for an increment of 5 minutes.
Some time examples on the 12 hour clock
00:00 is -=-
03:00 is --=-
06:00 is ---=-
21:40 is 09:40 is ----=---..
All minutes are rounded to 5 minutes, therefore the str representations of the following times are equal
00:00 is 00:01 is .. is 00:04