osd-contiki/apps/time/resource_timezone.c
Ralf Schlatterbeck 0068611b4d Implement localtime
Now we manage a timezone and daylight-savings aware version of
localtime. We parse UNIX timezone strings. The default (active after the
first call to localtime or localtime_r) is CET/CEST, the timezone of
Europe/Vienna. The wallclock-time osd-example demonstrates how to set a
different timezone via the timezone resource.

Note: After startup no timezone is set. So in this state querying the
timezone resource will return an empty string. After first call to
localtime (if not timezone has been set via the timezone resource) a
query to timezone will return the default timezone string for CET/CEST.

The string returned by the localtime and utc timezones now also includes
the timezone name.

New fields tm_gmtoff and tm_zone were added to the tm structure. These
are available in BSD systems and when setting special compiler
definitions on Linux.

Note: the timezone offset information in the tm structure (tm_gmtoff)
as well as in the tz structure returned by gettimeofday (tz_minuteswest)
may be wrong sign, this code is largely untested.
2016-02-18 09:55:07 +01:00

47 lines
758 B
C

/**
* \file
* Resource for timezone handling
* \author
* Ralf Schlatterbeck <rsc@runtux.com>
*
* \brief get/put timezone string
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "contiki.h"
#include "time.h"
#include "time_resource.h"
#include "jsonparse.h"
#include "er-coap.h"
#include "generic_resource.h"
void timezone_from_string (const char *name, const char *s)
{
set_tz (s);
}
size_t
timezone_to_string (const char *name, uint8_t is_json, char *buf, size_t bsize)
{
if (get_tz (buf, bsize) == NULL) {
*buf = '\0';
}
return strlen (buf);
}
GENERIC_RESOURCE
( timezone
, TZ
, s
, timezone_from_string
, timezone_to_string
);
/*
* VI settings, see coding style
* ex:ts=8:et:sw=2
*/