Skip to content

Commit

Permalink
date: simplify test package
Browse files Browse the repository at this point in the history
  • Loading branch information
jcar87 committed Nov 12, 2024
1 parent 9a8c80d commit 8233c6e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 79 deletions.
4 changes: 2 additions & 2 deletions recipes/date/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.8)
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES CXX)

find_package(date REQUIRED CONFIG)
find_package(date REQUIRED)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE date::date)
Expand Down
57 changes: 6 additions & 51 deletions recipes/date/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -1,62 +1,17 @@
#include "date/date.h"
#include "date/tz.h"

#include <chrono>
#include <cstdlib>
#include <iostream>
#include <type_traits>

class ZoneOffset {
public:
explicit ZoneOffset(std::chrono::minutes offset)
: _offset(offset) {}

template <class Duration>
auto to_local(date::sys_time<Duration> tp) const
-> date::local_time<typename std::common_type<Duration, std::chrono::minutes>::type> {
using namespace date;
using namespace std::chrono;
using LT = date::local_time<typename std::common_type<Duration, minutes>::type>;
return LT{(tp + _offset).time_since_epoch()};
}

template <class Duration>
auto to_sys(date::local_time<Duration> tp) const
-> date::sys_time<typename std::common_type<Duration, std::chrono::minutes>::type> {
using namespace date;
using namespace std::chrono;
using ST = date::sys_time<typename std::common_type<Duration, minutes>::type>;
return ST{(tp - _offset).time_since_epoch()};
}

private:
std::chrono::minutes _offset;
};

int main() {
using std::chrono::hours;
using std::chrono::milliseconds;
using std::chrono::minutes;
using namespace date;

auto date1 = 2015_y/March/22;
std::cout << date1 << '\n';
auto date2 = March/22/2015;
std::cout << date2 << '\n';
auto date3 = 22_d/March/2015;
std::cout << date3 << '\n';

ZoneOffset p3_45{hours{3} + minutes{45}};
zoned_time<milliseconds, ZoneOffset*> zt{&p3_45, floor<milliseconds>(std::chrono::system_clock::now())};
std::cout << zt.get_sys_time() << " (sys time)\n";
std::cout << zt.get_local_time() << " (local time)\n";
const date::year_month_day conan_two(date::year(2023), date::month(2), date::day(22));
std::cout << "Conan was released on: " << conan_two << std::endl;

#ifndef DATE_HEADER_ONLY
try {
auto tz = date::current_zone()->name();
std::cout << "timezone: " << tz << std::endl;
} catch (const std::exception & e) {
std::cout << "exception caught " << e.what() << std::endl;
const date::time_zone* tz = date::current_zone();
}
catch (const std::exception & e) {
std::cout << "exception caught " << e.what() << std::endl;
}
#endif

Expand Down
8 changes: 0 additions & 8 deletions recipes/date/all/test_v1_package/CMakeLists.txt

This file was deleted.

18 changes: 0 additions & 18 deletions recipes/date/all/test_v1_package/conanfile.py

This file was deleted.

0 comments on commit 8233c6e

Please sign in to comment.