-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathholocene.go
More file actions
59 lines (51 loc) · 1.13 KB
/
Copy pathholocene.go
File metadata and controls
59 lines (51 loc) · 1.13 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"fmt"
"os"
"strconv"
"strings"
"time"
)
func toAstronomical(year int) int {
// AD years (1 AD = 1, etc.)
if year >= 1 {
return year
}
// BC years: input year = -N means "N BC"
// But astronomical year 0 = 1 BC
// So: N BC -> astronomical year = -(N - 1)
// Example: -500 -> 500 BC -> astronomical year = -(500 - 1) = -499
return -(abs(year) - 1)
}
func abs(x int) int {
if x < 0 {
return -x
}
return x
}
func work(year int) {
astYear := toAstronomical(year)
holocene := astYear + 10000
fmt.Printf("Input year: %d -> Astronomical year: %d -> Holocene Era: %d HE : column %d\n",
year, astYear, holocene, holocene/100)
}
func main() {
var year int
var err error
// If year provided on command line:
if len(os.Args) > 1 {
parts := strings.Split(os.Args[1], ",")
for _, part := range parts {
year, err = strconv.Atoi(part)
if err != nil {
fmt.Println("Error: Year must be an integer. Use negative numbers for BC.")
return
}
work(year)
}
} else {
// Otherwise use the current year
year = time.Now().Year()
work(year)
}
}