Skip to content

Commit 2984d3f

Browse files
authored
Merge pull request #1 from EmilFonGaz/main
upload time library
2 parents 27c5dd1 + 6610470 commit 2984d3f

18 files changed

+7302
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.depend
2+
*.layout
3+
*.o
4+
*.exe

code_blocks/build/build.cbp

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
2+
<CodeBlocks_project_file>
3+
<FileVersion major="1" minor="6" />
4+
<Project>
5+
<Option title="build" />
6+
<Option pch_mode="2" />
7+
<Option compiler="copy_of_mingw_64_7_3_0" />
8+
<Build>
9+
<Target title="Debug">
10+
<Option output="../../lib/ztime_x64" prefix_auto="1" extension_auto="1" />
11+
<Option working_dir="" />
12+
<Option object_output="obj/Debug/" />
13+
<Option type="2" />
14+
<Option compiler="mingw_64_7_3_0" />
15+
<Option createDefFile="1" />
16+
<Compiler>
17+
<Add option="-Wall" />
18+
<Add option="-g" />
19+
</Compiler>
20+
</Target>
21+
<Target title="Release">
22+
<Option output="../../lib/ztime_x64" prefix_auto="1" extension_auto="1" />
23+
<Option working_dir="" />
24+
<Option object_output="obj/Release/" />
25+
<Option type="2" />
26+
<Option compiler="mingw_64_7_3_0" />
27+
<Option createDefFile="1" />
28+
<Compiler>
29+
<Add option="-O2" />
30+
<Add option="-Wall" />
31+
<Add option="-std=c++11" />
32+
<Add directory="../../src" />
33+
</Compiler>
34+
<Linker>
35+
<Add option="-s" />
36+
<Add directory="../../src" />
37+
</Linker>
38+
</Target>
39+
</Build>
40+
<Unit filename="../../src/ztime.cpp" />
41+
<Unit filename="../../src/ztime.hpp" />
42+
<Extensions>
43+
<code_completion />
44+
<envvars />
45+
<debugger />
46+
<lib_finder disable_auto="1" />
47+
</Extensions>
48+
</Project>
49+
</CodeBlocks_project_file>

code_blocks/example_sync/curl-ca-bundle.crt

+3,338
Large diffs are not rendered by default.
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
2+
<CodeBlocks_project_file>
3+
<FileVersion major="1" minor="6" />
4+
<Project>
5+
<Option title="example_sync" />
6+
<Option pch_mode="2" />
7+
<Option compiler="mingw_64_7_3_0" />
8+
<Build>
9+
<Target title="Debug">
10+
<Option output="bin/Debug/example_sync" prefix_auto="1" extension_auto="1" />
11+
<Option object_output="obj/Debug/" />
12+
<Option type="1" />
13+
<Option compiler="mingw_64_7_3_0" />
14+
<Compiler>
15+
<Add option="-g" />
16+
</Compiler>
17+
</Target>
18+
<Target title="Release">
19+
<Option output="example_sync" prefix_auto="1" extension_auto="1" />
20+
<Option object_output="obj/Release/" />
21+
<Option type="1" />
22+
<Option compiler="mingw_64_7_3_0" />
23+
<Compiler>
24+
<Add option="-O2" />
25+
<Add option="-std=c++11" />
26+
<Add directory="../../lib/curl-7.60.0-win64-mingw/bin" />
27+
<Add directory="../../lib/curl-7.60.0-win64-mingw/include" />
28+
<Add directory="../../src" />
29+
</Compiler>
30+
<Linker>
31+
<Add option="-s" />
32+
<Add library="../../lib/curl-7.60.0-win64-mingw/lib/libcurl.a" />
33+
<Add library="../../lib/curl-7.60.0-win64-mingw/lib/libcurl.dll.a" />
34+
<Add directory="../../lib/curl-7.60.0-win64-mingw/bin" />
35+
<Add directory="../../lib/curl-7.60.0-win64-mingw/include" />
36+
<Add directory="../../lib/curl-7.60.0-win64-mingw/lib" />
37+
<Add directory="../../src" />
38+
</Linker>
39+
</Target>
40+
</Build>
41+
<Compiler>
42+
<Add option="-Wall" />
43+
<Add option="-fexceptions" />
44+
</Compiler>
45+
<Unit filename="../../src/ztime.cpp" />
46+
<Unit filename="../../src/ztime.hpp" />
47+
<Unit filename="../../src/ztime_sync.hpp" />
48+
<Unit filename="main.cpp" />
49+
<Extensions>
50+
<code_completion />
51+
<envvars />
52+
<debugger />
53+
<lib_finder disable_auto="1" />
54+
</Extensions>
55+
</Project>
56+
</CodeBlocks_project_file>
2.48 MB
Binary file not shown.
979 KB
Binary file not shown.
403 KB
Binary file not shown.

code_blocks/example_sync/main.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <iostream>
2+
#include <ztime_sync.hpp>
3+
4+
int main() {
5+
std::cout << "Hello world!" << std::endl;
6+
ztime::TimeSync iTimeSync;
7+
while(!iTimeSync.is_time_sync()) {
8+
std::this_thread::sleep_for(std::chrono::seconds(1));
9+
};
10+
11+
ztime::ftimestamp_t last_utc = iTimeSync.get_ftimestamp();
12+
while(true) {
13+
ztime::ftimestamp_t real_utc = iTimeSync.get_ftimestamp();
14+
ztime::ftimestamp_t pc_utc = ztime::get_ftimestamp();
15+
if(real_utc - last_utc > 0.1) {
16+
std::cout << "accuracy: " << iTimeSync.get_accuracy() << " sync utc: " << ztime::get_str_time_ms(real_utc) << " pc utc: " << ztime::get_str_time_ms(pc_utc) << "\r";
17+
last_utc = real_utc;
18+
}
19+
};
20+
return 0;
21+
}
22+

code_blocks/test/julian_date.cpp

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include <iostream>
2+
#include <ztime.hpp>
3+
4+
using namespace std;
5+
6+
int main() {
7+
std::cout << "calc: " << (int64_t)(ztime::get_julian_date(17.5, 5, 2021)*100) << std::endl;
8+
std::cout << "calc (2459351.9623843): " << (int64_t)(ztime::get_julian_date(17, 5, 2021, 11, 5, 50)*10000000) << std::endl;
9+
std::cout << "calc (2459351.9623843): " << (int64_t)(ztime::get_julian_date(ztime::get_ftimestamp(17, 5, 2021, 11, 5, 50))*10000000) << std::endl;
10+
11+
std::cout << "calc (2459352.004): " << (int64_t)(ztime::get_julian_date(17, 5, 2021, 12, 5, 50)*1000) << std::endl;
12+
std::cout << "calc (2459351.962): " << (int64_t)(ztime::get_julian_date(17, 5, 2021, 11, 5, 50)*1000) << std::endl;
13+
14+
std::cout << "(4.81, 10, 1957) to jd = 2436116.31, calc: " << (int64_t)(ztime::get_julian_date(4.81, 10, 1957)*100) << std::endl;
15+
if ((int64_t)(ztime::get_julian_date(4.81, 10, 1957)*100) != 243611631) {
16+
std::cout << "error" << std::endl;
17+
return 0;
18+
}
19+
20+
std::cout << "(17, 5, 2021) to jd = 2459351.50, calc: " << (int64_t)(ztime::get_julian_date(17, 5, 2021)*100) << std::endl;
21+
if ((int64_t)(ztime::get_julian_date(17, 5, 2021)*100) != 245935150) {
22+
std::cout << "error" << std::endl;
23+
return 0;
24+
}
25+
26+
std::cout << "(1, 1, 2021) to jd = 2459215.5, calc: " << (int64_t)(ztime::get_julian_date(1, 1, 2021)*100) << std::endl;
27+
if ((int64_t)(ztime::get_julian_date(1, 1, 2021)*100) != 245921550) {
28+
std::cout << "error" << std::endl;
29+
return 0;
30+
}
31+
32+
std::cout << "(17, 5, 2021) to jd = 2459352, calc: " << (int64_t)(ztime::get_julian_day_number(17, 5, 2021)) << std::endl;
33+
if (ztime::get_julian_day_number(17, 5, 2021) != 2459352) {
34+
std::cout << "error " << ztime::get_julian_day_number(17, 5, 2021) << std::endl;
35+
return 0;
36+
}
37+
38+
std::cout << "2299160.5, calc: " << (int64_t)(ztime::get_julian_day_number(15, 10, 1582)*100) << std::endl;
39+
std::cout << "2440588, calc: " << (int64_t)(ztime::get_julian_day_number(1, 1, 1970)*100) << std::endl;
40+
std::cout << "2451796, calc: " << (int64_t)(ztime::get_julian_day_number(9, 9, 2000)*100) << std::endl;
41+
std::cout << "2459352, calc: " << (int64_t)(ztime::get_julian_day_number(17, 5, 2021)*100) << std::endl;
42+
std::cout << "2451544, calc: " << (int64_t)(ztime::get_julian_day_number(1, 1, 2000)*100) << std::endl;
43+
44+
std::cout << "a " << ((14LL - 1) / 12LL) << " a2 " << ((14.0d - (double)1) / 12.0d) << std::endl;
45+
46+
std::cout << "2440588, calc: " << (int64_t)(ztime::get_julian_date(1, 1, 1970, 0, 00, 00) * 1) << std::endl;
47+
std::cout << "2459351.5, calc: " << (int64_t)(ztime::get_julian_date(17, 5, 2021, 0, 00, 00) * 1) << std::endl;
48+
std::cout << "2459352.4524884, calc: " << (int64_t)(ztime::get_julian_date(17, 5, 2021, 22, 51, 35) * 1000000) << std::endl;
49+
std::cout << "2451545.25, calc: " << (int64_t)(ztime::get_julian_date(1, 1, 2000, 18, 00, 00) * 100) << std::endl;
50+
std::cout << "2451544.9989583, calc: " << (int64_t)(ztime::get_julian_date(1, 1, 2000, 11, 58, 30) * 1000000) << std::endl;
51+
return 0;
52+
}

code_blocks/test/moon_phase.cpp

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <iostream>
2+
#include <ztime.hpp>
3+
4+
using namespace std;
5+
6+
int main() {
7+
ztime::MoonPhase moon_phase;
8+
moon_phase.init(ztime::get_ftimestamp(18, 5, 2021, 0, 0,0));
9+
std::cout << "age: " << moon_phase.age << std::endl;
10+
std::cout << "age_in_degrees: " << moon_phase.age_in_degrees << std::endl;
11+
std::cout << "phase: " << moon_phase.phase << std::endl;
12+
13+
std::cout << "get_moon_phase: " << ztime::get_moon_phase(ztime::get_ftimestamp(18, 5, 2021, 0, 0, 0)) << std::endl;
14+
std::cout << "get_moon_phase: " << ztime::get_moon_phase_v2(ztime::get_ftimestamp(18, 5, 2021, 0, 0, 0)) << std::endl;
15+
std::cout << "get_moon_age: " << (ztime::get_moon_age(ztime::get_ftimestamp(18, 5, 2021, 0, 0,0))) << std::endl;
16+
17+
std::cout << "get_moon_phase: " << ztime::get_moon_phase_v2(ztime::get_ftimestamp(10, 6, 2021, 10, 54, 0)) << std::endl;
18+
std::cout << "get_moon_phase: " << ztime::get_moon_phase(ztime::get_ftimestamp(10, 6, 2021, 10, 54, 0)) << std::endl;
19+
20+
std::cout << "is_new_moon (false): " << moon_phase.is_new_moon(ztime::get_ftimestamp(11, 5, 2021, 19, 00, 0)) << std::endl;
21+
std::cout << "is_new_moon (true): " << moon_phase.is_new_moon(ztime::get_ftimestamp(11, 5, 2021, 19, 01, 0)) << std::endl;
22+
std::cout << "is_new_moon (false): " << moon_phase.is_new_moon(ztime::get_ftimestamp(11, 5, 2021, 19, 02, 0)) << std::endl;
23+
24+
std::cout << "is_new_moon (false): " << moon_phase.is_new_moon(ztime::get_ftimestamp(10, 6, 2021, 10, 53, 0)) << std::endl;
25+
std::cout << "is_new_moon (true): " << moon_phase.is_new_moon(ztime::get_ftimestamp(10, 6, 2021, 10, 54, 0)) << std::endl;
26+
std::cout << "is_new_moon (false): " << moon_phase.is_new_moon(ztime::get_ftimestamp(10, 6, 2021, 10, 55, 0)) << std::endl;
27+
28+
std::cout << "is_new_moon (false): " << moon_phase.is_new_moon(ztime::get_ftimestamp(11, 5, 2021, 19, 00, 0)) << std::endl;
29+
std::cout << "is_new_moon (true): " << moon_phase.is_new_moon(ztime::get_ftimestamp(11, 5, 2021, 19, 01, 0)) << std::endl;
30+
std::cout << "is_new_moon (false): " << moon_phase.is_new_moon(ztime::get_ftimestamp(11, 5, 2021, 19, 02, 0)) << std::endl;
31+
32+
std::cout << "is_full_moon (false): " << moon_phase.is_full_moon(ztime::get_ftimestamp(26, 5, 2021, 11, 13, 0)) << std::endl;
33+
std::cout << "is_full_moon (true): " << moon_phase.is_full_moon(ztime::get_ftimestamp(26, 5, 2021, 11, 14, 0)) << std::endl;
34+
std::cout << "is_full_moon (false): " << moon_phase.is_full_moon(ztime::get_ftimestamp(26, 5, 2021, 11, 15, 0)) << std::endl;
35+
36+
std::cout << "calc_phase_v3: " << moon_phase.calc_phase_v3(ztime::get_ftimestamp(18, 5, 2021, 0, 0, 0)) << std::endl;
37+
std::cout << "calc_phase_v3: " << moon_phase.calc_phase_v3(ztime::get_ftimestamp(11, 5, 2021, 19, 00, 0)) << std::endl;
38+
std::cout << "calc_phase_v3: " << moon_phase.calc_phase_v3(ztime::get_ftimestamp(11, 5, 2021, 19, 01, 0)) << std::endl;
39+
std::cout << "calc_phase_v3: " << moon_phase.calc_phase_v3(ztime::get_ftimestamp(11, 5, 2021, 19, 02, 0)) << std::endl;
40+
41+
std::cout << "get_moon_minute: " << moon_phase.get_moon_minute(ztime::get_ftimestamp(18, 5, 2021, 0, 0, 0)) << std::endl;
42+
std::cout << "get_moon_minute: " << moon_phase.get_moon_minute(ztime::get_ftimestamp(11, 5, 2021, 19, 00, 0)) << std::endl;
43+
std::cout << "get_moon_minute: " << moon_phase.get_moon_minute(ztime::get_ftimestamp(11, 5, 2021, 19, 01, 0)) << std::endl;
44+
std::cout << "get_moon_minute: " << moon_phase.get_moon_minute(ztime::get_ftimestamp(11, 5, 2021, 19, 01, 40)) << std::endl;
45+
std::cout << "get_moon_minute: " << moon_phase.get_moon_minute(ztime::get_ftimestamp(11, 5, 2021, 19, 02, 0)) << std::endl;
46+
return 0;
47+
}

code_blocks/test/parse.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <iostream>
2+
#include <ztime.hpp>
3+
4+
using namespace std;
5+
6+
int main() {
7+
ztime::timestamp_t timestamp = 0;
8+
ztime::convert_str_to_timestamp("08.08.2021 23:59:59", timestamp);
9+
std::cout << "convert-1 08.08.2021 23:59:59 == " << ztime::get_str_date_time(timestamp) << std::endl;
10+
11+
timestamp = 0;
12+
ztime::convert_str_to_timestamp("23:59:59", timestamp);
13+
std::cout << "convert-2 23:59:59 == " << ztime::get_str_date_time(timestamp) << std::endl;
14+
15+
std::cout << "convert-3 23:59:59 == " << ztime::get_str_date_time(ztime::to_timestamp("23:59:59")) << std::endl;
16+
std::cout << "convert-4 23:59:59 == " << ztime::get_str_time(ztime::to_second_day("23:59:59")) << std::endl;
17+
std::cout << "convert-5 23:59:00 == " << ztime::get_str_time(ztime::to_second_day("23:59")) << std::endl;
18+
std::cout << "convert-4 23:00:00 == " << ztime::get_str_time(ztime::to_second_day("23")) << std::endl;
19+
std::cout << "convert-4b 26:00:00 == " << ztime::to_second_day("26") << std::endl;
20+
21+
std::cout << "convert-5 08.08.2021 23:59:59 == " << ztime::get_str_date_time(ztime::to_timestamp("08.08.2021 23:59:59")) << std::endl;
22+
std::cout << "convert-6 08.08.2021 23:59:00 == " << ztime::get_str_date_time(ztime::to_timestamp("08.08.2021 23:59")) << std::endl;
23+
std::cout << "convert-6 08.08.2021 23:59:00 == " << ztime::get_str_date_time(ztime::to_timestamp("2021.08.08 23:59")) << std::endl;
24+
25+
return 0;
26+
}

code_blocks/test/test.cbp

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
2+
<CodeBlocks_project_file>
3+
<FileVersion major="1" minor="6" />
4+
<Project>
5+
<Option title="test" />
6+
<Option pch_mode="2" />
7+
<Option compiler="mingw_64_7_3_0" />
8+
<Build>
9+
<Target title="moon_phase">
10+
<Option output="bin/Release/moon_phase" prefix_auto="1" extension_auto="1" />
11+
<Option object_output="obj/Release/" />
12+
<Option type="1" />
13+
<Option compiler="mingw_64_7_3_0" />
14+
<Compiler>
15+
<Add option="-O2" />
16+
<Add directory="../../src" />
17+
</Compiler>
18+
<Linker>
19+
<Add option="-s" />
20+
<Add directory="../../src" />
21+
</Linker>
22+
</Target>
23+
<Target title="julian_date">
24+
<Option output="bin/Release/moon_phase" prefix_auto="1" extension_auto="1" />
25+
<Option object_output="obj/Release/" />
26+
<Option type="1" />
27+
<Option compiler="mingw_64_7_3_0" />
28+
<Compiler>
29+
<Add option="-O2" />
30+
<Add directory="../../src" />
31+
</Compiler>
32+
<Linker>
33+
<Add option="-s" />
34+
<Add directory="../../src" />
35+
</Linker>
36+
</Target>
37+
<Target title="parse">
38+
<Option output="bin/Release/moon_phase" prefix_auto="1" extension_auto="1" />
39+
<Option object_output="obj/Release/" />
40+
<Option type="1" />
41+
<Option compiler="mingw_64_7_3_0" />
42+
<Compiler>
43+
<Add option="-O2" />
44+
<Add directory="../../src" />
45+
</Compiler>
46+
<Linker>
47+
<Add option="-s" />
48+
<Add directory="../../src" />
49+
</Linker>
50+
</Target>
51+
</Build>
52+
<Compiler>
53+
<Add option="-Wall" />
54+
<Add option="-fexceptions" />
55+
</Compiler>
56+
<Unit filename="../../src/ztime.cpp" />
57+
<Unit filename="../../src/ztime.hpp" />
58+
<Unit filename="../../src/ztime_cpu_time.hpp" />
59+
<Unit filename="julian_date.cpp">
60+
<Option target="julian_date" />
61+
</Unit>
62+
<Unit filename="moon_phase.cpp">
63+
<Option target="moon_phase" />
64+
</Unit>
65+
<Unit filename="parse.cpp">
66+
<Option target="parse" />
67+
</Unit>
68+
<Extensions />
69+
</Project>
70+
</CodeBlocks_project_file>

doc/logo.png

7.9 KB
Loading

doc/sync.png

1.38 KB
Loading

0 commit comments

Comments
 (0)