1 #ifndef _GO_DATETIME_H_
2 #define _GO_DATETIME_H_
3 
4 #include <goffice/goffice.h>
5 #include <time.h>
6 
7 G_BEGIN_DECLS
8 
9 /**
10  * GODateConventions:
11  * @use_1904: Base on 1904 as opposed to 1900.
12  */
13 struct _GODateConventions {
14 	gboolean use_1904;	/* Use MacOffice 1904 based date convention,
15 				 * Rather than the Win32 style 1900 */
16 };
17 
18 GType go_date_conventions_get_type (void);
19 
20 /*
21  * Naming conventions:
22  *
23  * "g": a GDate *.
24  * "timet": Unix' time_t.
25  * "serial": Excel serial day number.
26  * "serial_raw": serial plus time as fractional day.
27  */
28 
29 /* Week numbering methods */
30 /* 1:   Week starts on Sunday. Days before first Sunday are in week 0. */
31 /* 2:   Week starts on Monday. Days before first Monday are in week 0. */
32 /* 150: ISO 8601 week number. */
33 enum {
34 	GO_WEEKNUM_METHOD_SUNDAY = 1,
35 	GO_WEEKNUM_METHOD_MONDAY = 2,
36 	GO_WEEKNUM_METHOD_ISO = 150
37 };
38 
39 /* These do not round and produces fractional values, i.e., includes time.  */
40 double	go_date_timet_to_serial_raw  (time_t t, GODateConventions const *conv);
41 
42 /* These are date-only, no time.  */
43 int	go_date_timet_to_serial      (time_t t, GODateConventions const *conv);
44 int	go_date_g_to_serial	      (GDate const *date, GODateConventions const *conv);
45 void	go_date_serial_to_g	      (GDate *res, int serial, GODateConventions const *conv);
46 time_t	go_date_serial_to_timet      (int serial, GODateConventions const *conv);
47 int	go_date_serial_raw_to_serial (double raw);
48 
49 /* These are time-only assuming a 24h day.  It probably loses completely on */
50 /* days with summer time ("daylight savings") changes.  */
51 int go_date_timet_to_seconds (time_t t);
52 int go_date_serial_raw_to_seconds (double raw);
53 
54 /* Number of full months between date1 and date2. */
55 /* largest value s.t. g_date_add_months (date1, result) <= date2 */
56 /* except that if the day is decreased in g_date_add_monts, treat
57    that as > the date it is decreased to. */
58 /* ( go_date_g_months_between ( March 31, April 30 ) == 0
59      even though g_date_add_months ( Mar 31, 1 ) <= Apr 30.... */
60 int go_date_g_months_between (GDate const *date1, GDate const *date2);
61 /* Number of full years between date1 and date2. */
62 /* (g_date_add_years (date1, result) <= date2; largest such value. */
63 /*  treat add_years (29-feb, x) > 28-feb ) */
64 int go_date_g_years_between (GDate const *date1, GDate const *date2);
65 /* week number according to the given method. */
66 int go_date_weeknum (GDate const *date, int method);
67 
68 /**
69  * GOBasisType:
70  * @GO_BASIS_MSRB_30_360: US 30/360 (days in a month/days in a year)
71  * @GO_BASIS_ACT_ACT: actual days/actual days
72  * @GO_BASIS_ACT_360: actual days/360
73  * @GO_BASIS_ACT_365: actual days/365
74  * @GO_BASIS_30E_360: European 30/360
75  * @GO_BASIS_30Ep_360: ?
76  * @GO_BASIS_MSRB_30_360_SYM: ?
77  **/
78 typedef enum { /* see doc/fn-financial-basis.txt for details */
79 	GO_BASIS_MSRB_30_360     = 0,
80 	GO_BASIS_ACT_ACT         = 1,
81 	GO_BASIS_ACT_360         = 2,
82 	GO_BASIS_ACT_365         = 3,
83 	GO_BASIS_30E_360         = 4,
84 	GO_BASIS_30Ep_360        = 5,
85 	GO_BASIS_MSRB_30_360_SYM = 6         /* Gnumeric extension.  */
86 } GOBasisType;
87 #define go_basis_t GOBasisType /* for compatibility */
88 
89 gint32  go_date_days_between_basis (GDate const *from, GDate const *to, GOBasisType basis);
90 
91 /**
92  * GoCouponConvention:
93  * @freq: frequency.
94  * @basis: #GOBasisType
95  * @eom: end of month.
96  * @date_conv: #GODateConventions
97  **/
98 typedef struct {
99 	int	 freq;
100 	GOBasisType  basis;
101 	gboolean eom;
102 	GODateConventions const *date_conv;
103 } GoCouponConvention;
104 
105 void   go_coup_cd    (GDate *res, GDate const *settle, GDate const *mat,
106 		      int freq, gboolean eom, gboolean next);
107 double go_coupdays   (GDate const *settlement, GDate const *maturity,
108 		      GoCouponConvention const *conv);
109 double go_coupdaybs  (GDate const *settlement, GDate const *maturity,
110 		      GoCouponConvention const *conv);
111 double go_coupdaysnc (GDate const *settlement, GDate const *maturity,
112 		      GoCouponConvention const *conv);
113 
114 int go_date_convention_base (GODateConventions const *conv);
115 
116 const GODateConventions *go_date_conv_from_str (const char *s);
117 gboolean go_date_conv_equal (const GODateConventions *a, const GODateConventions *b);
118 double go_date_conv_translate (double f,
119 			       const GODateConventions *src,
120 			       const GODateConventions *dst);
121 
122 char *go_date_weekday_name (GDateWeekday wd, gboolean abbrev);
123 char *go_date_month_name (GDateMonth m, gboolean abbrev);
124 
125 
126 G_END_DECLS
127 
128 #endif /* _GO_DATETIME_H_ */
129