Skip to content

Commit 63f1f8d

Browse files
authored
feat: add combined scale and format conversion templates and bump to v0.5.3 (#17)
1 parent d94e6ff commit 63f1f8d

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.5.3] - 2026-06-06
9+
10+
### Added
11+
12+
- Added `to<TargetScale, TargetFormat>()` and `to_with<TargetScale, TargetFormat>(ctx)` templates to `Time` and `EncodedTime` for simultaneous scale and format conversion.
13+
814
## [0.5.2] - 2026-06-02
915

1016
### Changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.15)
2-
project(tempoch_cpp VERSION 0.5.2 LANGUAGES CXX)
2+
project(tempoch_cpp VERSION 0.5.3 LANGUAGES CXX)
33

44
set(CMAKE_CXX_STANDARD 17)
55
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include/tempoch/time_base.hpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,18 @@ template <typename S> class Time {
224224
return Time<TargetScale>(detail::scale_convert<S, TargetScale>(raw_, ctx.get()));
225225
}
226226

227+
template <typename TargetScale, typename TargetFormat,
228+
std::enable_if_t<is_scale_v<TargetScale> && is_format_v<TargetFormat>, int> = 0>
229+
EncodedTime<TargetScale, TargetFormat> to() const {
230+
return to<TargetScale>().template to<TargetFormat>();
231+
}
232+
233+
template <typename TargetScale, typename TargetFormat,
234+
std::enable_if_t<is_scale_v<TargetScale> && is_format_v<TargetFormat>, int> = 0>
235+
EncodedTime<TargetScale, TargetFormat> to_with(const TimeContext &ctx) const {
236+
return to_with<TargetScale>(ctx).template to_with<TargetFormat>(ctx);
237+
}
238+
227239
template <typename TargetFormat, std::enable_if_t<is_format_v<TargetFormat>, int> = 0>
228240
EncodedTime<S, TargetFormat> to() const {
229241
return EncodedTime<S, TargetFormat>(detail::quantity_from_raw<TargetFormat>(
@@ -343,11 +355,23 @@ template <typename S, typename F> class EncodedTime {
343355
return Time<S>::from_encoded(*this).template to<TargetScale>();
344356
}
345357

358+
template <typename TargetScale, typename TargetFormat,
359+
std::enable_if_t<is_scale_v<TargetScale> && is_format_v<TargetFormat>, int> = 0>
360+
EncodedTime<TargetScale, TargetFormat> to() const {
361+
return Time<S>::from_encoded(*this).template to<TargetScale, TargetFormat>();
362+
}
363+
346364
template <typename TargetScale, std::enable_if_t<is_scale_v<TargetScale>, int> = 0>
347365
Time<TargetScale> to_with(const TimeContext &ctx) const {
348366
return Time<S>::from_encoded_with(*this, ctx).template to_with<TargetScale>(ctx);
349367
}
350368

369+
template <typename TargetScale, typename TargetFormat,
370+
std::enable_if_t<is_scale_v<TargetScale> && is_format_v<TargetFormat>, int> = 0>
371+
EncodedTime<TargetScale, TargetFormat> to_with(const TimeContext &ctx) const {
372+
return Time<S>::from_encoded_with(*this, ctx).template to_with<TargetScale, TargetFormat>(ctx);
373+
}
374+
351375
template <typename TargetFormat, std::enable_if_t<is_format_v<TargetFormat>, int> = 0>
352376
EncodedTime<S, TargetFormat> to() const {
353377
return Time<S>::from_encoded(*this).template to<TargetFormat>();

0 commit comments

Comments
 (0)