selectel / tempo Goto Github PK
View Code? Open in Web Editor NEWNIF-based date and time parsing and formatting for Erlang
License: MIT License
NIF-based date and time parsing and formatting for Erlang
License: MIT License
The current implementation crashes with a badmatch
if a NIF doesn't return {ok, ...}
. A more user-friendly behaviour would be to bubble the error:
(tempo_dev@yooki)7> tempo:parse(rfc1123, {datetime, B}).
** exception error: no match of right hand side value {error,format_mismatch}
in function tempo:parse_datetime/2 (src/tempo.erl, line 115)
According to ISO8601, the time zone is represented either by ±HH, or ±HHMM, or by a single letter 'Z' for UTC.
In the code a simple %z is used, which omits the '±' delimiter. This is wrong and has to be corrected.
convert_format(iso8601) -> <<"%Y-%m-%dT%H:%M:%S%z">>;
strptime and strftime supports '%z' field descriptor, but:
tempo:strptime(<<"%z">>, <<"+03:00">>).
{ok, 0.0}tempo:strptime(<<"%H:%M:%S%z">>, <<"11:22:33+03:00">>).
{ok,40953.0}
tempo:strptime(<<"%H:%M:%S">>, <<"11:22:33">>).
{ok,40953.0}
Is it possible to expose timezone/UTC offset data?
It looks like strptime
and strftime
behaviour for dates before 1900 varies across platforms, so I think we should throw an error on such inputs.
(tempo_dev@yooki)13> tempo:parse(<<"%Y">>, {unix, <<"1505">>}). %% OS X
{error,format_mismatch}
Dear All
The title says it all. Here's the eunit output:
======================== EUnit ========================
undefined
*** test module not found ***
**tempo
=ERROR REPORT==== 11-Dec-2012::15:54:34 ===
The on_load function for module tempo returned {error,
{load_failed,
"Failed to load NIF library: 'dlopen(/Users/ivan/local/erlang/tempo_git/priv/tempo.so, 2): image not found'"}}
=======================================================
Attempting to run tempo fails with the same error. A symlink from priv/tempo.so to priv/tempo_drv.so makes everything ok.
I wonder if this is something to do with the rebar port compiler and compiling on macosx. I'e had a quick scan through rebar and google but not turned up anything.
(Apart from that, tempo is a /very/ handy piece of code!)
Best wishes
Ivan
I think we should choose between /2
and /3
functions and remove parse_*
and format_*
from the export list -- there should be only one way of doing things.
При попытке откомпилировать c помощью rebar compile на Ubuntu Server 14.04 под Erlang 17.3 и установленном gcc 4.8.2 выдает след. ошибки:
"
.../deps/tempo/c_src/tempo.c:163:5: error: missing initializer for field ‘flags’ of ‘ErlNifFunc’ [-Werror=missing-field-initializers]
{"strptime", 2, tempo_strptime},
^
In file included from /opt/test/kf_portal/deps/tempo/c_src/tempo.c:3:0:
/usr/local/lib/erlang/erts-6.2/include/erl_nif.h:132:14: note: ‘flags’ declared here
unsigned flags;
^
.../deps/tempo/c_src/tempo.c:164:5: error: missing initializer for field ‘flags’ of ‘ErlNifFunc’ [-Werror=missing-field-initializers]
{"strftime", 2, tempo_strftime}
^
In file included from /opt/test/kf_portal/deps/tempo/c_src/tempo.c:3:0:
/usr/local/lib/erlang/erts-6.2/include/erl_nif.h:132:14: note: ‘flags’ declared here
unsigned flags;
^
.../deps/tempo/c_src/tempo.c: In function ‘nif_init’:
.../deps/tempo/c_src/tempo.c:168:1: error: missing initializer for field ‘options’ of ‘ErlNifEntry’ [-Werror=missing-field-initializers]
ERL_NIF_INIT(tempo, tempo_funcs, &load, &reload, &upgrade, &unload)
^
In file included from /opt/test/kf_portal/deps/tempo/c_src/tempo.c:3:0:
/usr/local/lib/erlang/erts-6.2/include/erl_nif.h:148:14: note: ‘options’ declared here
unsigned options;
^
cc1: all warnings being treated as errors
"
Решается заменой строки {port_env, [{"CFLAGS", "$CFLAGS -std=gnu99 -Wall -Wextra -Werror -pedantic"}]}.
на {port_env, [{"CFLAGS", "$CFLAGS -std=gnu99 -w -pedantic"}]}.
в rebar.config
It is impossible to parse string with milliseconds.
For example:
(tempo_dev@garry-desktop)22> tempo:parse(iso8601, {datetime, <<"2012-06-16T08:25:34.123+01:00">>}).
** exception error: no match of right hand side value {error,format_mismatch}
in function tempo:parse_datetime/2 (src/tempo.erl, line 115)
Also, there is no way to set right format, because strptime and strftime do not support milliseconds.
Hello I think the official edown repo is https://github.com/uwiger/edown .
Also is a bad idea to use master on dependencies. Instead use a stable version
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.