Skip to content

Commit

Permalink
lua: built-in module datetime
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
tsafin committed Jul 27, 2021
1 parent f8f6ae8 commit 50175cb
Show file tree
Hide file tree
Showing 10 changed files with 1,288 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ lua_source(lua_sources ../third_party/luafun/fun.lua)
lua_source(lua_sources lua/httpc.lua)
lua_source(lua_sources lua/iconv.lua)
lua_source(lua_sources lua/swim.lua)
lua_source(lua_sources lua/datetime.lua)

# LuaJIT jit.* library
lua_source(lua_sources ${LUAJIT_SOURCE_ROOT}/src/jit/bc.lua)
lua_source(lua_sources ${LUAJIT_SOURCE_ROOT}/src/jit/bcsave.lua)
Expand Down
21 changes: 21 additions & 0 deletions src/exports.h
Original file line number Diff line number Diff line change
Expand Up @@ -531,3 +531,24 @@ EXPORT(uri_format)
EXPORT(uri_parse)
EXPORT(uuid_nil)
EXPORT(uuid_unpack)
EXPORT(dt_from_rdn)
EXPORT(dt_from_yd)
EXPORT(dt_from_ymd)
EXPORT(dt_from_yqd)
EXPORT(dt_from_ywd)
EXPORT(dt_to_yd)
EXPORT(dt_to_ymd)
EXPORT(dt_to_yqd)
EXPORT(dt_to_ywd)
EXPORT(dt_rdn)
EXPORT(dt_dow)
EXPORT(dt_parse_iso_date)
EXPORT(dt_parse_iso_time)
EXPORT(dt_parse_iso_time_basic)
EXPORT(dt_parse_iso_time_extended)
EXPORT(dt_parse_iso_zone)
EXPORT(dt_parse_iso_zone_basic)
EXPORT(dt_parse_iso_zone_extended)
EXPORT(dt_parse_iso_zone_lenient)
EXPORT(dt_from_struct_tm)
EXPORT(dt_to_struct_tm)
61 changes: 61 additions & 0 deletions src/lib/core/datetime.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#pragma once
/*
* Copyright 2021, Tarantool AUTHORS, please see AUTHORS file.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* 1. Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

#include <c-dt/dt_core.h>
#include <stdint.h>
#include <stdbool.h>

#if defined(__cplusplus)
extern "C" {
#endif /* defined(__cplusplus) */

/**
* datetime structure consisting of:
*/
struct datetime_t {
int64_t secs; ///< seconds since epoch
int32_t nsec; ///< nanoseconds if any
int32_t offset; ///< offset in minutes from GMT
};

/**
* Date/time delta structure
*/
struct datetime_interval_t {
int64_t secs; ///< relative seconds delta
int32_t nsec; ///< nanoseconds delta
};

#if defined(__cplusplus)
} /* extern "C" */
#endif /* defined(__cplusplus) */

Loading

0 comments on commit 50175cb

Please sign in to comment.