• This repository has been archived on 10/Sep/2023
  • Stars
    star
    148
  • Rank 249,983 (Top 5 %)
  • Language
    C
  • License
    Apache License 2.0
  • Created over 9 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Cron expression parsing in ANSI C

Cron expression parsing in ANSI C

travis appveyor

Given a cron expression and a date, you can get the next date which satisfies the cron expression.

Supports cron expressions with seconds field. Based on implementation of CronSequenceGenerator from Spring Framework.

Compiles and should work on Linux (GCC/Clang), Mac OS (Clang), Windows (MSVC), Android NDK, iOS and possibly on other platforms with time.h support.

Supports compilation in C (89) and in C++ modes.

Usage example

#include "ccronexpr.h"

cron_expr expr;
const char* err = NULL;
memset(&expr, 0, sizeof(expr));
cron_parse_expr("0 */2 1-4 * * *", &expr, &err);
if (err) ... /* invalid expression */
time_t cur = time(NULL);
time_t next = cron_next(&expr, cur);

Compilation and tests run examples

gcc ccronexpr.c ccronexpr_test.c -I. -Wall -Wextra -std=c89 -DCRON_TEST_MALLOC -o a.out && ./a.out
g++ ccronexpr.c ccronexpr_test.c -I. -Wall -Wextra -std=c++11 -DCRON_TEST_MALLOC -o a.out && ./a.out
g++ ccronexpr.c ccronexpr_test.c -I. -Wall -Wextra -std=c++11 -DCRON_TEST_MALLOC -DCRON_COMPILE_AS_CXX -o a.out && ./a.out

clang ccronexpr.c ccronexpr_test.c -I. -Wall -Wextra -std=c89 -DCRON_TEST_MALLOC -o a.out && ./a.out
clang++ ccronexpr.c ccronexpr_test.c -I. -Wall -Wextra -std=c++11 -DCRON_TEST_MALLOC -o a.out && ./a.out
clang++ ccronexpr.c ccronexpr_test.c -I. -Wall -Wextra -std=c++11 -DCRON_TEST_MALLOC -DCRON_COMPILE_AS_CXX -o a.out && ./a.out

cl ccronexpr.c ccronexpr_test.c /W4 /D_CRT_SECURE_NO_WARNINGS && ccronexpr.exe

Examples of supported expressions

Expression, input date, next date:

"*/15 * 1-4 * * *",  "2012-07-01_09:53:50", "2012-07-02_01:00:00"
"0 */2 1-4 * * *",   "2012-07-01_09:00:00", "2012-07-02_01:00:00"
"0 0 7 ? * MON-FRI", "2009-09-26_00:42:55", "2009-09-28_07:00:00"
"0 30 23 30 1/3 ?",  "2011-04-30_23:30:00", "2011-07-30_23:30:00"

See more examples in tests.

Timezones

This implementation does not support explicit timezones handling. By default all dates are processed as UTC (GMT) dates without timezone infomation.

To use local dates (current system timezone) instead of GMT compile with -DCRON_USE_LOCAL_TIME, example:

gcc -DCRON_USE_LOCAL_TIME ccronexpr.c ccronexpr_test.c -I. -Wall -Wextra -std=c89 -DCRON_TEST_MALLOC -o a.out && TZ="America/Toronto" ./a.out

License information

This project is released under the Apache License 2.0.

Changelog

2019-03-27

  • CRON_USE_LOCAL_TIME usage fixes

2018-05-23

  • merged #8
  • merged #9
  • minor cleanups

2018-01-27

  • merged #6
  • updated license file (to the one parse-able by github)

2017-09-24

  • merged #4

2016-06-17

  • use thread-safe versions of gmtime and localtime

2015-02-28

  • initial public version

More Repositories

1

staticlib_pion

Embedded async HTTP 1.1 server based on a source code from https://github.com/splunk/pion
C++
12
star
2

cmake

CMake scripts for Staticlibs projects
CMake
9
star
3

staticlib_cron

Cron expressions library for Staticlibs
C++
5
star
4

staticlib_http

Staticlibs HTTP client library
C++
3
star
5

staticlib_tinydir

Staticlibs directory reader library
C++
2
star
6

staticlib_compress

Staticlibs Compress library
C++
2
star
7

lookaside_jansson

jansson CentOS lookaside sources
Shell
1
star
8

external_bmalloc

bmalloc library build for Staticlibs
CMake
1
star
9

lookaside_libharu

libharu Fedora EPEL lookaside sources
C
1
star
10

external_libjpeg-turbo

libjpeg-turbo library build for Staticlibs
C
1
star
11

external_libgit2

libgit2 library build for Staticlibs
CMake
1
star
12

staticlib_io

Staticlibs IO library
C++
1
star
13

external_portaudio

PortAudio library build for Staticlibs
CMake
1
star
14

external_libpq

libpq library build for Staticlibs
C
1
star
15

nginx-windows-build

[Work in progress]
Shell
1
star
16

external_utf8cpp

UTF8-CPP library wrapper for Staticlibs
CMake
1
star
17

staticlib_mustache

Staticlibs Mustache library
C++
1
star
18

tools_windows_tcl

Tcl/Tk binaries
Tcl
1
star
19

mirror_utf8cpp

Unofficial mirror of http://svn.code.sf.net/p/utfcpp/code/v2_0/
C++
1
star
20

external_soci

SOCI library build for Staticlibs
CMake
1
star
21

external_jansson

Jansson JSON library build for Staticlibs
CMake
1
star
22

mirror_portaudio

Unofficial mirror of https://subversion.assembla.com/svn/portaudio/portaudio/
C
1
star
23

staticlib_websocket

Staticlibs WebSocket library
C++
1
star
24

external_asio

Asio C++ library wrapper for Staticlibs
CMake
1
star
25

tools_windows_python27

Python 2.7.13 windows x86 binaries
Python
1
star
26

tools_windows_curl

cURL 7.61 windows x86 binaries
C
1
star
27

lookaside_xz

xz CentOS lookaside sources
C
1
star
28

lookaside_curl

curl CentOS lookaside sources
C
1
star
29

lookaside_zlib

zlib CentOS lookaside sources
C
1
star
30

lookaside_libssh2

libssh2 CentOS lookaside sources
C
1
star
31

external_curl

cURL library build for Staticlibs
C
1
star
32

staticlib_config

Staticlibs Config macros
C++
1
star
33

external_openssl

OpenSSL library build for Staticlibs
CMake
1
star
34

external_freetype

Freetype library build for Staticlibs
CMake
1
star
35

external_giflib

giflib library build for Staticlibs
C
1
star
36

external_quickjs

QuickJS library build for Staticlibs
C
1
star
37

external_libssh2

libssh2 library build for Staticlibs
C
1
star
38

external_hpdf

libharu library build for Staticlibs
CMake
1
star
39

lookaside_openssl

openssl CentOS lookaside sources
C
1
star
40

nginx-json-handler

Nginx content handler that calls shared library passing request in JSON
C
1
star
41

staticlib_utils

Staticlibs common utilities library
C++
1
star
42

lookaside_postgresql

postgresql Fedora lookaside sources
C
1
star
43

external_sqlite

SQLite library build for Staticlibs
C
1
star
44

lookaside_popt

popt CentOS lookaside sources
Shell
1
star
45

external_libpng

libpng library build for Staticlibs
CMake
1
star
46

staticlib_unzip

Staticlibs unZIP library
C++
1
star
47

external_xz

XZ library build for Staticlibs
C
1
star
48

external_popt

popt library build for Staticlibs
CMake
1
star
49

external_duktape

Duktape library build for Staticlibs
C
1
star