A C++ header-only library for creating, displaying, iterating and manipulating dates

Related tags

Miscellaneous asap
Overview

The ASAP date/time library for beautiful C++ code

ASAP is a small, header-only date-time library for C++11 and beyond. It is heavily inspired by my great time using momentjs to parse and display dates. ASAP has a lot of syntatic sugar to make your code look pretty both on the inside and outside :)

All ASAP examples available online at repl.it. (main() starts at line 533)

Features

  • A date/time class to handle dates and time (duh)
  • A duration class to handle unbounded periods (e.g, asap::day(1) specifies a day)
  • A period class to handle bounded periods (e.g, asap::period(asap::now(), asap::tomorrow()))
  • Lots of syntatic sugar (e.g, auto then = asap::now() + asap::week(1))
  • Literals (e.g, auto then = asap::now() + 1_year) for seconds, minutes, hours, days, weeks, months and years
  • Broken down duration printing (e.g, asap::days(10) prints "1 week, 3 days")
  • Range-based iteration for periods:
   for (auto x: asap::now().until(asap::tomorrow()).every(1_hour)) {
        std::cout << x << std::endl;
   }

Index

  • asap::datetime class docs to learn about date/time
  • asap::duration class docs will teach you about durations and their literals
  • asap::period class docs to learn about periods and date/time iterations
  • literals.h docs has the asap::literals namespace with all ASAP literals

Using

You can either:

  • Drop the include/asap folder in your project and use it
  • Make your compiler aware of the include/asap folder and include "asap.h" in your code
  • If using CMake you can add the project subdirectory and link against it using target_link_libraries
  • Use find_package if you installed ASAP using make install or any other method
  • Download the latest release which is a single asap.h file bundled with all the classes.

License

ASAP is MIT licensed.

You might also like...
Creating sepia, reflection, grayscale, and blur filters from scratch and returns a modified image

image-filter Created sepia, reflection, grayscale, and blur filters from scratch and returning a modified image Directories: images: contains sample i

A terse, flexible language and runtime for creating and executing visual novels.

Fabulist A terse, flexible language and runtime for creating and executing visual novels. Contributing We're open to contributions from anyone and eve

A header-only library for C++(0x) that allows automagic pretty-printing of any container.

cxx-prettyprint =============== A pretty printing library for C++ containers. Synopsis: Simply by including this header-only library in your sourc

Cross-platform C++11 header-only library for memory mapped file IO

mio An easy to use header-only cross-platform C++11 memory mapping library with an MIT license. mio has been created with the goal to be easily includ

A Minimal, Header only Modern c++ library for terminal goodies 💄✨
A Minimal, Header only Modern c++ library for terminal goodies 💄✨

rang Colors for your Terminal. Windows Demo Example usage #include "rang.hpp" using namespace std; using namespace rang; int main() { cout "P

AssociatedEnum: header-only library for C++ for enumerations with associated values

asenum AssociatedEnum is a header-only library for C++ for enumerations with associated values asenum is C++ implementation of very neat enums from Sw

A header only library that provides parser combinators to C++

This is an experimental C++ library for rapidly building parsers. It is inspired by parser combinators in haskell such as attoparsec and, like those libraries, allows for the construction of fully fledged parsers in a few lines of code.

Small Extremely Powerful Header Only C++ Lexical Analyzer/String Parser Library
Small Extremely Powerful Header Only C++ Lexical Analyzer/String Parser Library

lexpp Small Extremely Powerful Header Only C++ Lexical Analyzer/String Parser Library Lexpp is made with simplicity and size in mind. The entire libra

Header-only library providing unicode aware string support for C++

CsString Introduction CsString is a standalone library which provides unicode aware string support. The CsBasicString class is a templated class which

Comments
  • Remove all single letter literals

    Remove all single letter literals

    Most of the single letter literals were uppercase and that is not allowed by the standard and caused compilation error on GCC 7.3.0 (cygwin). Also we cannot just make all of them lowercase because of the month/minute conflict.

    opened by igorrafael 1
  • Build failure on Mac OS 11 beta (Clang 12)

    Build failure on Mac OS 11 beta (Clang 12)

    ❯ bazel test ...
    ...
    ERROR: /Users/yesudeep/code/bwuck/third_party/cc/test/BUILD.bazel:93:10: C++ compilation of rule '//third_party/cc/test:asap_example' failed (Exit 1): wrapped_clang failed: error executing command 
    ...
    Use --sandbox_debug to see verbose messages from the sandbox wrapped_clang failed: error executing command 
      (cd /private/var/tmp/_bazel_yesudeep/148f9f6ebca6e47e7d6d5ed427a82e62/sandbox/darwin-sandbox/61/execroot/__main__ && \
      exec env - \
        APPLE_SDK_PLATFORM=MacOSX \
        APPLE_SDK_VERSION_OVERRIDE=11.0 \
        XCODE_VERSION_OVERRIDE=12.0.0.12A8189h \
      external/local_config_cc/wrapped_clang '-D_FORTIFY_SOURCE=1' -fstack-protector -fcolor-diagnostics -Wall -Wthread-safety -Wself-assign -fno-omit-frame-pointer -O0 -DDEBUG '-std=c++11' -iquote . -iquote bazel-out/darwin-fastbuild/bin -iquote external/fmt -iquote bazel-out/darwin-fastbuild/bin/external/fmt -iquote external/mobius3_asap -iquote bazel-out/darwin-fastbuild/bin/external/mobius3_asap -iquote external/bazel_tools -iquote bazel-out/darwin-fastbuild/bin/external/bazel_tools -isystem external/fmt/include -isystem bazel-out/darwin-fastbuild/bin/external/fmt/include -isystem external/mobius3_asap/include -isystem bazel-out/darwin-fastbuild/bin/external/mobius3_asap/include -MD -MF bazel-out/darwin-fastbuild/bin/third_party/cc/test/_objs/asap_example/asap_example.d '-frandom-seed=bazel-out/darwin-fastbuild/bin/third_party/cc/test/_objs/asap_example/asap_example.o' -isysroot __BAZEL_XCODE_SDKROOT__ -F__BAZEL_XCODE_SDKROOT__/System/Library/Frameworks -F__BAZEL_XCODE_DEVELOPER_DIR__/Platforms/MacOSX.platform/Developer/Library/Frameworks '-mmacosx-version-min=11.0' -DHAVE_BAZEL_BUILD '-std=c++2a' -Wall -Wreturn-type -Wuninitialized -Wunused-result '-Werror=narrowing' '-Werror=reorder' -Wunused-local-typedefs '-Werror=conversion-null' '-Werror=overlength-strings' '-Werror=pointer-arith' '-Werror=varargs' '-Werror=vla' '-Werror=write-strings' -Wmissing-declarations '-fdiagnostics-color=always' -no-canonical-prefixes -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -c third_party/cc/test/asap_example.cc -o bazel-out/darwin-fastbuild/bin/third_party/cc/test/_objs/asap_example/asap_example.o)
    Execution platform: @local_config_platform//:host
    
    Use --sandbox_debug to see verbose messages from the sandbox
    third_party/cc/test/asap_example.cc:11:15: error: use of overloaded operator '!=' is ambiguous (with operand types 'asap::detail::accessor<3600>::iterator' and 'asap::detail::accessor<3600>::iterator')
      for (auto d : period.every(asap::hour(2))) {
                  ^
    external/mobius3_asap/include/asap/period.tcc:49:16: note: candidate function
              bool operator!=(const iterator & other);
                   ^
    external/mobius3_asap/include/asap/period.tcc:48:16: note: candidate function
              bool operator==(const iterator & other);
                   ^
    external/mobius3_asap/include/asap/period.tcc:48:16: note: candidate function (with reversed parameter order)
    third_party/cc/test/asap_example.cc:11:17: note: in implicit call to 'operator!=' for iterator of type 'asap::detail::accessor<3600>'
      for (auto d : period.every(asap::hour(2))) {
                    ^~~~~~
    external/mobius3_asap/include/asap/period.tcc:52:28: note: selected 'begin' function with iterator type 'accessor<3600>::iterator'
            accessor::iterator begin() const;
                               ^
    1 error generated.
    INFO: Elapsed time: 2.658s, Critical Path: 2.15s
    INFO: 15 processes: 15 darwin-sandbox.
    FAILED: Build did NOT complete successfully
    

    Example code:

    #include "asap/asap.h"
    #include "fmt/core.h"
    #include "fmt/format.h"
    
    int
    main() {
      auto now    = asap::now();
      auto period = now.until(asap::tomorrow());
      for (auto d : period.every(asap::hour(2))) {
        fmt::print("* {}\n", d.str());
      }
      return 0;
    }
    
    opened by yesudeep 2
Releases(v1.0.0)
Owner
Leonardo Guilherme de Freitas
Leonardo Guilherme de Freitas
An embedded system for displaying current number of followers on bilibili. A reproduction of eInkBoard v1. 一个能显示哔哩哔哩账号实时粉丝数的嵌入式系统,eInkBoard v1 的复刻版。

eInkBoard v2 An embedded system for displaying current number of followers on bilibili. A reproduction of eInkBoard v1 (this page is in Chinese). 一个能显

Karbon Chen 4 Dec 6, 2021
Displaying @colorschemez tweets on 2.4" TFT display

colorschemez display This code takes the most recent tweet from the twitter account @colorschemez, and displays it onto a 2.4" TFT display. If you use

null 2 Dec 28, 2021
An improved plot widget for Dear ImGui, aimed at displaying audio data

imgui-plot An improved plot widget for Dear ImGui, aimed at displaying audio data TOC Screenshots Rationale Usage Installation FAQ Screenshots Display

Anton Lobashev 399 Jan 3, 2023
Tuibox - A single-header terminal UI (TUI) library, capable of creating mouse-driven, interactive applications on the command line.

tuibox tuibox ("toybox") is a single-header terminal UI library, capable of creating mouse-driven, interactive applications on the command line. It is

Andrew 37 Dec 24, 2022
a one header library for creating Lua bindings to C++

Description A C++ library for generating Lua bindings. Supported features: functions, constructors, inheritance, member functions, properties, standar

null 76 Aug 20, 2022
2D physics header-only library for videogames developed in C using raylib library.

Physac Physac is a small 2D physics engine written in pure C. The engine uses a fixed time-step thread loop to simluate physics. A physics step contai

Víctor Fisac 241 Dec 28, 2022
Small and dirty header-only library that supports user input with some more advanced features than in the standard lib.

dirty-term Small and dirty header-only library that supports user input with some more advanced features than in the standard lib. This small, lightwe

null 3 Apr 24, 2022
A minimal header-only audio synthesis and processing library

Aurora A minimal header-only C++ audio synthesis and processing toolkit. Getting Started Aurora is a collection of header files which can be included

null 11 Sep 26, 2022
DimensionalAnalysis - A compact C++ header-only library providing compile-time dimensional analysis and unit awareness

Dimwits ...or DIMensional analysis With unITS is a C++14 library for compile-time dimensional analysis and unit awareness. Minimal Example #include <i

NJOY 8 Jul 8, 2022