-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdateandtimeutils.bash
47 lines (41 loc) · 1.11 KB
/
dateandtimeutils.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env bash
#
# File:
# dateandtimeutils.bash
#
# Description:
# Bash date and time utilities
#
# ============================================
# Conversion
# ============================================
# Convert seconds to milliseconds with decimal precision.
# Usage:
# secondsToMillisecondsDecimal <seconds>
secondsToMillisecondsDecimal() {
printf '%.4f' "$(bc <<< "${1}*1000")"
}
# Convert seconds to milliseconds.
# Usage:
# secondsToMilliseconds <seconds>
# Notes:
# The number is rounded to the nearest tenths place using half toward zero
# rounding mode.
secondsToMilliseconds() {
printf '%.0f' "$(secondsToMillisecondsDecimal "${1}")"
}
# Convert seconds to microseconds with decimal precision.
# Usage:
# secondsToMicrosecondsDecimal <seconds>
secondsToMicrosecondsDecimal() {
printf '%.4f' "$(bc <<< "${1}*1000000")"
}
# Convert seconds to microseconds.
# Usage:
# secondsToMicroseconds <seconds>
# Notes:
# The number is rounded to the nearest tenths place using half toward zero
# rounding mode.
secondsToMicroseconds() {
printf '%.0f' "$(secondsToMicrosecondsDecimal "${1}")"
}