Pure Programmer
Blue Matrix


Cluster Map

Project: Duration Class

Write a mutable class to represent a time duration. Your class should represent time durations in the following units: ns, µs, ms, s, min, hour, day, week, month, year. Use an enumeration to represent the time duration units. You should have a default constructor that sets the internal value to 0. Write a setter that takes a value and an enumeration value for units. Include a getter that takes an enumeration value for units and returns the value in that measurement unit.

Output
$ python3 DurationClass.py 1.23e+09 ns 1.23e+06 µs 1230 ms 1.23 sec 0.0205 min 0.000341667 hour 1.42361e-05 day 2.03373e-06 week 4.67716e-07 month 3.89763e-08 year 3.15576e+16 ns 3.15576e+13 µs 3.15576e+10 ms 3.15576e+07 sec 525960 min 8766 hour 365.25 day 52.1786 week 12 month 1 year 1 ns 0.001 µs 1e-06 ms 1e-09 sec 1.66667e-11 min 2.77778e-13 hour 1.15741e-14 day 1.65344e-15 week 3.80257e-16 month 3.16881e-17 year

Solution