Browse Source

Dummy custom Date provider example

user-stack-check-macro
Sami Vaarala 9 years ago
parent
commit
36cef9a2c1
  1. 5
      examples/dummy-date-provider/README.rst
  2. 27
      examples/dummy-date-provider/dummy_date_provider.c

5
examples/dummy-date-provider/README.rst

@ -0,0 +1,5 @@
====================================
Dummy external Date provider example
====================================
This example implements a dummy, minimal external Date provider.

27
examples/dummy-date-provider/dummy_date_provider.c

@ -0,0 +1,27 @@
/*
* Dummy Date provider
*
* There are two minimally required macros which you must provide in
* duk_config.h:
*
* extern duk_double_t dummy_get_now(void);
*
* #define DUK_USE_DATE_GET_NOW(ctx) dummy_get_now()
* #define DUK_USE_DATE_GET_LOCAL_TZOFFSET(d) 0
*
* Note that since the providers are macros, you don't need to use
* all arguments. Similarly, you can "return" fixed values as
* constants. Above, local timezone offset is always zero i.e.
* we're always in UTC.
*
* You can also provide optional macros to parse and format timestamps
* in a platform specific format. If not provided, Duktape will use
* ISO 8601 only (which is often good enough).
*/
#include "duktape.h"
duk_double_t dummy_get_now(void) {
/* Return a fixed time here as a dummy example. */
return -11504520000.0;
}
Loading…
Cancel
Save