2018-01-20 14:32:42 -06:00
/*
* t i m e 64 . i - - S W I G interface file for type t r a n s l a t i o n of t i m e 64 t y p e s
*
* C o p y r i g h t ( C ) 2008 P a r I T W o r k e r C o - o p e r a t i v e < p a r i t i n f o @ p a r i t . c a >
*
* T h i s p r o g r a m is f r e e s o f t w a r e ; y o u c a n r e d i s t r i b u t e i t and / or
* m o d i f y i t u n d e r t h e t e r m s of t h e G N U G e n e r a l Public L i c e n s e as
* p u b l i s h e d by t h e F r e e S o f t w a r e F o u n d a t i o n ; e i t h e r version 2 of
* t h e L i c e n s e , or ( at y o u r option ) any l a t e r version .
*
* T h i s p r o g r a m is d i s t r i b u t e d in t h e h o p e t h a t i t w i l l b e u s e f u l ,
* b u t W I T H O U T ANY W A R R A N T Y ; w i t h o u t e v e n t h e i m p l i e d w a r r a n t y of
* M E R C H A N T A B I L I T Y or F I T N E S S FOR A P A R T I C U L A R P U R P O S E . S e e t h e
* G N U G e n e r a l Public L i c e n s e for m o r e d e t a i l s .
*
* Y o u s h o u l d h a v e r e c e i v e d a c o p y of t h e G N U G e n e r a l Public L i c e n s e
* a l o n g with t h i s p r o g r a m ; if not , c o n t a c t :
*
* F r e e S o f t w a r e F o u n d a t i o n V o i c e : + 1 - 617 - 542 - 5942
* 51 F r a n k l i n S t r e e t , F i f t h F l o o r F a x : + 1 - 617 - 542 - 2652
* B o s t o n , M A 02110 - 1301 , U S A g n u @ g n u . o r g
*
* @ a u t h o r M a r k J e n k i n s , P a r I T W o r k e r C o - o p e r a t i v e < m a r k @ p a r i t . c a >
* /
/* * @ f i l e
@ b r i e f S W I G interface file for type t r a n s l a t i o n of t i m e 64 t y p e s
@ a u t h o r M a r k J e n k i n s , P a r I T W o r k e r C o - o p e r a t i v e < m a r k @ p a r i t . c a >
@ a u t h o r J e f f G r e e n , P a r I T W o r k e r C o - o p e r a t i v e < j e f f @ p a r i t . c a >
@ i n g r o u p p y t h o n _ b i n d i n g s * /
// A typemap for converting python dates to time64 in functions that
// require time64 as an argument
% t y p e m a p ( in ) t i m e 64 {
P y D a t e T i m e _ I M P O R T ;
2019-04-06 00:51:15 -05:00
if ( ! P y D a t e T i m e _ C h e c k ( $ input ) && !PyInt_Check($input)) {
P y E r r _ S e t S t r i n g ( P y E x c _ V a l u e E r r o r , "datetime or integer expected" ) ;
return NULL ;
}
if ( P y D a t e T i m e _ C h e c k ( $ input ) ) {
s t r u c t t m time = { P y D a t e T i m e _ D A T E _ G E T _ S E C O N D ( $ i n p u t ) ,
P y D a t e T i m e _ D A T E _ G E T _ M I N U T E ( $ input ) ,
P y D a t e T i m e _ D A T E _ G E T _ H O U R ( $ input ) ,
P y D a t e T i m e _ G E T _ D A Y ( $ input ) ,
P y D a t e T i m e _ G E T _ M O N T H ( $ input ) - 1 ,
P y D a t e T i m e _ G E T _ Y E A R ( $ input ) - 1900 } ;
$ 1 = g n c _ m k t i m e ( &time);
} else {
$ 1 = P y I n t _ A s L o n g ( $ input ) ;
}
2018-01-20 14:32:42 -06:00
}
// A typemap for converting python dates to time64 *, for functions that
// requires a time64 * as an argument. BIG ASSUMPTION, the function
// receiving this pointer is going to make a copy of the data. After the
// function call, the memory for the time64 used to perform this conversion
// is going to be lost, so make damn sure that the recipient of this pointer
// is NOT going dereference it sometime after this function call takes place.
//
// As far as I know, the xaccTransSetDate[Posted|Entered|Due]TS functions
// from Transaction.h are the only functions with time64 * that we re
// actually using. I have personally verified in the source that the pointer
// being produced by this typemap is being dereferenced, and the data copied
// in all three functions.
//
// The memory for the time64 used for this conversion is allocated on the
// stack. (SWIG will name the variables ts1, ts2, ts3...)
//
// Mark Jenkins <mark@parit.ca>
% t y p e m a p ( in ) t i m e 64 * ( t i m e 64 s e c s ) {
P y D a t e T i m e _ I M P O R T ;
2019-04-06 00:51:15 -05:00
if ( ! P y D a t e T i m e _ C h e c k ( $ input ) && !PyInt_Check($input)) {
P y E r r _ S e t S t r i n g ( P y E x c _ V a l u e E r r o r , "datetime or integer expected" ) ;
return NULL ;
}
if ( P y D a t e T i m e _ C h e c k ( $ input ) ) {
s t r u c t t m time = { P y D a t e T i m e _ D A T E _ G E T _ S E C O N D ( $ i n p u t ) ,
P y D a t e T i m e _ D A T E _ G E T _ M I N U T E ( $ input ) ,
P y D a t e T i m e _ D A T E _ G E T _ H O U R ( $ input ) ,
P y D a t e T i m e _ G E T _ D A Y ( $ input ) ,
P y D a t e T i m e _ G E T _ M O N T H ( $ input ) - 1 ,
P y D a t e T i m e _ G E T _ Y E A R ( $ input ) - 1900 } ;
t i m e 64 s e c s = g n c _ m k t i m e ( &time);
$ 1 = &secs;
} else {
t i m e 64 s e c s = P y I n t _ A s L o n g ( $ input ) ;
$ 1 = &secs;
}
2018-01-20 14:32:42 -06:00
}
// A typemap for converting time64 values returned from functions to
// python dates. Note that we can't use Python DateTime's fromtimestamp function because it relies upon libc's localtime. Note also that while we create times with timegm we retrieve it with localtime
% t y p e m a p ( o u t ) t i m e 64 {
2018-10-06 16:59:52 -05:00
if ( $ 1 = = I N T 64 _ M A X ) {
$ r e s u l t = P y _ N o n e ;
} else {
P y D a t e T i m e _ I M P O R T ;
s t r u c t t m t ;
g n c _ l o c a l t i m e _ r ( &$1, &t);
$ r e s u l t = P y D a t e T i m e _ F r o m D a t e A n d T i m e ( t . t m _ y e a r + 1900 , t . t m _ m o n + 1 ,
t . t m _ m d a y , t . t m _ h o u r , t . t m _ m i n ,
t . t m _ s e c , 0 ) ;
}
2018-01-20 14:32:42 -06:00
}