Don't behave as if avail_d was not hardcoded, it is hardcoded
[claws.git] / src / plugins / vcalendar / icaltime_as_local.c
1 /* Taken as is from http://dev.w3.org/cvsweb/Ical2html/icaltime_as_local.c
2 W3C® SOFTWARE NOTICE AND LICENSE
3
4
5 Copyright © 1994-2002 World Wide Web Consortium, (Massachusetts
6 Institute of Technology, Institut National de Recherche en
7 Informatique et en Automatique, Keio University). All Rights
8 Reserved. http://www.w3.org/Consortium/Legal/
9
10 This W3C work (including software, documents, or other related items)
11 is being provided by the copyright holders under the following
12 license. By obtaining, using and/or copying this work, you (the
13 licensee) agree that you have read, understood, and will comply with
14 the following terms and conditions:
15
16 Permission to use, copy, modify, and distribute this software and its
17 documentation, with or without modification, for any purpose and
18 without fee or royalty is hereby granted, provided that you include
19 the following on ALL copies of the software and documentation or
20 portions thereof, including modifications, that you make:
21
22 The full text of this NOTICE in a location viewable to users of the
23 redistributed or derivative work.  Any pre-existing intellectual
24 property disclaimers, notices, or terms and conditions. If none exist,
25 a short notice of the following form (hypertext is preferred, text is
26 permitted) should be used within the body of any redistributed or
27 derivative code: "Copyright © [$date-of-software] World Wide Web
28 Consortium, (Massachusetts Institute of Technology, Institut National
29 de Recherche en Informatique et en Automatique, Keio University). All
30 Rights Reserved. http://www.w3.org/Consortium/Legal/" Notice of any
31 changes or modifications to the W3C files, including the date changes
32 were made. (We recommend you provide URIs to the location from which
33 the code is derived.)
34
35 THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT
36 HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED,
37 INCLUDING BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY OR FITNESS
38 FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE OR
39 DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS,
40 TRADEMARKS OR OTHER RIGHTS.
41
42 COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL
43 OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE OR
44 DOCUMENTATION.
45
46 The name and trademarks of copyright holders may NOT be used in
47 advertising or publicity pertaining to the software without specific,
48 written prior permission. Title to copyright in this software and any
49 associated documentation will at all times remain with copyright
50 holders.
51
52 ____________________________________
53
54 This formulation of W3C's notice and license became active on August
55 14 1998 so as to improve compatibility with GPL. This version ensures
56 that W3C software licensing terms are no more restrictive than GPL and
57 consequently W3C software may be distributed in GPL packages. See the
58 older formulation for the policy prior to this date. Please see our
59 Copyright FAQ for common questions about using materials from our
60 site, including specific terms and conditions for packages like
61 libwww, Amaya, and Jigsaw. Other questions about this notice can be
62 directed to site-policy@w3.org.
63 */
64 /*
65  * Convert a date/time in UTC to a date/time in the local time zone.
66  * (Seems to be missing from libical v 0.23)
67  *
68  * Author: Bert Bos <bert@w3.org>
69  * Created: 18 Dec 2002
70  * Version: $Id$
71  */
72
73 #ifdef HAVE_CONFIG_H
74 #  include "config.h"
75 #include "claws-features.h"
76 #endif
77
78 #include <stddef.h>
79 #include <glib.h>
80 #include <glib/gi18n.h>
81
82 #ifdef USE_PTHREAD
83 #include <pthread.h>
84 #endif
85
86 #include "icaltime_as_local.h"
87
88 #if !HAVE_ICALTIME_AS_LOCAL
89
90 struct icaltimetype icaltime_as_local(struct icaltimetype tt)
91 {
92   time_t t;
93   struct tm *tm;
94   struct icaltimetype h;
95   struct tm buft;
96
97   t = icaltime_as_timet(tt);                    /* Convert to epoch */
98 #ifdef G_OS_WIN32
99   if (t < 0)
100           t = 1;
101 #endif
102   tm = localtime_r(&t, &buft);                  /* Convert to local time */
103   h.year = tm->tm_year + 1900;                  /* Make an icaltimetype */
104   h.month = tm->tm_mon + 1;
105   h.day = tm->tm_mday;
106   h.hour = tt.is_date ? 0 : tm->tm_hour;
107   h.minute = tt.is_date ? 0 : tm->tm_min;
108   h.second = tt.is_date ? 0 : tm->tm_sec;
109   h.is_utc = 0;
110   h.is_date = tt.is_date;
111   return h;
112 }
113
114 #endif
115