aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_eorzea_time.rs
blob: d9b7cefb45ba6327ed284b0a1168ab35f52281a3 (plain) (blame)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
extern crate ffxiv_chronowatcher;

use ffxiv_chronowatcher::eorzean_time::{convert_to_eorzean_date, convert_to_eorzean_time, earth_sec_to_eorzea_duration, eorzea_duration_to_earth_sec, EorzeanTime, EorzeanDate};
use chrono::DateTime;

mod time_tests {
    use super::*;
    #[test]
    fn test_convert_to_eorzean_date_astral() {
        let unix_timestamp = 141414141414;
        let eorzean_date = convert_to_eorzean_date(unix_timestamp);
        assert_eq!(eorzean_date.years, 87682);
        assert_eq!(eorzean_date.suns, 18);
        assert_eq!(eorzean_date.bells, 16);
        assert_eq!(eorzean_date.minutes, 4);
        assert_eq!(eorzean_date.guardian, "Llymlaen");
        assert_eq!(eorzean_date.phase, "Full Moon");
        assert_eq!(eorzean_date.moon, "Third Astral Moon");
    }

    #[test]
    fn test_convert_to_ez_chrono_datetime(){
        let timestamp: i64 = 141414141414;
        let chrono_date = DateTime::from_timestamp(timestamp, 0).expect("Failed to create DateTime");
        let eorzean_date = convert_to_eorzean_date(chrono_date);
        assert_eq!(eorzean_date.years, 87682);
        assert_eq!(eorzean_date.suns, 18);
        assert_eq!(eorzean_date.bells, 16);
        assert_eq!(eorzean_date.minutes, 4);
        assert_eq!(eorzean_date.guardian, "Llymlaen");
        assert_eq!(eorzean_date.phase, "Full Moon");
        assert_eq!(eorzean_date.moon, "Third Astral Moon");
    }

    #[test]
    fn test_convert_eorzean_date_umbral() {
        let unix_timestamp = 11223344;
        let eorzean_date = convert_to_eorzean_date(unix_timestamp);
        assert_eq!(eorzean_date.years, 6);
        assert_eq!(eorzean_date.suns, 17);
        assert_eq!(eorzean_date.bells, 5);
        assert_eq!(eorzean_date.minutes, 23);
        assert_eq!(eorzean_date.guardian, "Althyk");
        assert_eq!(eorzean_date.phase, "Full Moon");
        assert_eq!(eorzean_date.moon, "Sixth Umbral Moon");
    }

    #[test]
    fn test_convert_to_eorzean_time() {
        let unix_timestamp = 1661114514;
        let time_tuple = convert_to_eorzean_time(unix_timestamp);
        assert_eq!(time_tuple.0, 10);
        assert_eq!(time_tuple.1, 56);
    }

    #[test]
    fn test_earth_sec_to_eorzea_sec(){
        let test_seconds = 70*60; // 70 minutes in seconds, should eq 1 sun = 86400 EZ sec
        let eorzean_duration = earth_sec_to_eorzea_duration(test_seconds);
        assert_eq!(eorzean_duration.suns, 1);
        assert_eq!(eorzean_duration.years, 0);
        assert_eq!(eorzean_duration.moons, 0);
        assert_eq!(eorzean_duration.weeks, 0);
        assert_eq!(eorzean_duration.bells, 0);
        assert_eq!(eorzean_duration.minutes, 0);
    }

    #[test]
    fn test_eorzea_dur_to_earth_sec() {
        let test_ez_time = EorzeanTime{
            years: 0,
            moons: 0,
            weeks: 1,
            suns: 1,
            bells: 0,
            minutes: 0,
            seconds: 0
        };
        // 37800 seconds in Earth time
        let seconds = eorzea_duration_to_earth_sec(test_ez_time);
        assert_eq!(seconds, 37800);
    }
}

send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage