Changed LICENSE. Now referenced to web site and file on project root directory
[anna.git] / example / time / conversor / main.cpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite                           //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7
8
9 #include <iostream>
10 #include <string>
11 #include <unistd.h>
12 #include <stdlib.h>
13
14 #include <anna/time/Date.hpp>
15 #include <anna/time/functions.hpp>
16
17 using namespace anna;
18
19 void F_exit(const char *message) {
20    std::cout << std::endl;
21    std::cout << std::endl;
22    std::cout << message << std::endl;
23    std::cout << std::endl;
24    std::cout << std::endl;
25    exit(0);
26 }
27
28 int main(int argc, char** argv) {
29    anna::time::functions::initialize();
30    std::cout << std::endl;
31    std::cout << std::endl;
32    std::cout << "BASIC CONVERSIONS" << std::endl;
33
34    // option
35    if (!argv[1]) {
36       std::string msg = "Use: ";
37       msg += argv[0];
38       msg += " [-unix <unix timestamp>] [-ntp <ntp timestamp>] [-yyyymmddHHmmss <yyyymmddHHmmss (in the system timezone)>]";
39       F_exit(msg.c_str());
40    }
41
42    std::string option = argv[1];
43
44    if (option != "-unix" && option != "-ntp" && option != "-yyyymmddHHmmss") F_exit("Only -unix/-ntp/-yyyymmddHHmmss options supported !");
45
46    // value
47    if (!argv[2]) {
48       F_exit("Missing value parameter !");
49    }
50
51    std::string value = argv[2];
52    // CONVERSION
53    anna::time::Date aux;
54
55    if (option == "-unix") {
56       aux.storeUnix(atoi(value.c_str()));
57    } else if (option == "-ntp") {
58       aux.storeNtp(atoi(value.c_str()));
59    } else if (option == "-yyyymmddHHmmss") {
60       aux.store(value);
61    }
62
63    std::cout << aux.asString() << std::endl;
64    F_exit("The End !");
65 }
66