Skip to content

Commit 50175cb

Browse files
committed
lua: built-in module datetime
* created a new Tarantool built-in module `datetime`; * register cdef types for this module; * export some `dt_*` functions from `c-dt` library; * lua implementationis of `asctime` and `strftime`; * datetime parsing unit tests, with and withput timezones; * c test for reversible strftime roundtrip; Part of tarantool#5941
1 parent f8f6ae8 commit 50175cb

File tree

10 files changed

+1288
-1
lines changed

10 files changed

+1288
-1
lines changed

src/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ lua_source(lua_sources ../third_party/luafun/fun.lua)
5151
lua_source(lua_sources lua/httpc.lua)
5252
lua_source(lua_sources lua/iconv.lua)
5353
lua_source(lua_sources lua/swim.lua)
54+
lua_source(lua_sources lua/datetime.lua)
55+
5456
# LuaJIT jit.* library
5557
lua_source(lua_sources ${LUAJIT_SOURCE_ROOT}/src/jit/bc.lua)
5658
lua_source(lua_sources ${LUAJIT_SOURCE_ROOT}/src/jit/bcsave.lua)

src/exports.h

+21
Original file line numberDiff line numberDiff line change
@@ -531,3 +531,24 @@ EXPORT(uri_format)
531531
EXPORT(uri_parse)
532532
EXPORT(uuid_nil)
533533
EXPORT(uuid_unpack)
534+
EXPORT(dt_from_rdn)
535+
EXPORT(dt_from_yd)
536+
EXPORT(dt_from_ymd)
537+
EXPORT(dt_from_yqd)
538+
EXPORT(dt_from_ywd)
539+
EXPORT(dt_to_yd)
540+
EXPORT(dt_to_ymd)
541+
EXPORT(dt_to_yqd)
542+
EXPORT(dt_to_ywd)
543+
EXPORT(dt_rdn)
544+
EXPORT(dt_dow)
545+
EXPORT(dt_parse_iso_date)
546+
EXPORT(dt_parse_iso_time)
547+
EXPORT(dt_parse_iso_time_basic)
548+
EXPORT(dt_parse_iso_time_extended)
549+
EXPORT(dt_parse_iso_zone)
550+
EXPORT(dt_parse_iso_zone_basic)
551+
EXPORT(dt_parse_iso_zone_extended)
552+
EXPORT(dt_parse_iso_zone_lenient)
553+
EXPORT(dt_from_struct_tm)
554+
EXPORT(dt_to_struct_tm)

src/lib/core/datetime.h

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#pragma once
2+
/*
3+
* Copyright 2021, Tarantool AUTHORS, please see AUTHORS file.
4+
*
5+
* Redistribution and use in source and binary forms, with or
6+
* without modification, are permitted provided that the following
7+
* conditions are met:
8+
*
9+
* 1. Redistributions of source code must retain the above
10+
* copyright notice, this list of conditions and the
11+
* following disclaimer.
12+
*
13+
* 2. Redistributions in binary form must reproduce the above
14+
* copyright notice, this list of conditions and the following
15+
* disclaimer in the documentation and/or other materials
16+
* provided with the distribution.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
19+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22+
* <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
26+
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
29+
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30+
* SUCH DAMAGE.
31+
*/
32+
33+
#include <c-dt/dt_core.h>
34+
#include <stdint.h>
35+
#include <stdbool.h>
36+
37+
#if defined(__cplusplus)
38+
extern "C" {
39+
#endif /* defined(__cplusplus) */
40+
41+
/**
42+
* datetime structure consisting of:
43+
*/
44+
struct datetime_t {
45+
int64_t secs; ///< seconds since epoch
46+
int32_t nsec; ///< nanoseconds if any
47+
int32_t offset; ///< offset in minutes from GMT
48+
};
49+
50+
/**
51+
* Date/time delta structure
52+
*/
53+
struct datetime_interval_t {
54+
int64_t secs; ///< relative seconds delta
55+
int32_t nsec; ///< nanoseconds delta
56+
};
57+
58+
#if defined(__cplusplus)
59+
} /* extern "C" */
60+
#endif /* defined(__cplusplus) */
61+

0 commit comments

Comments
 (0)