Skip to content

Commit 3fabd54

Browse files
eodtime bugfix, improved error catching at rollover (#31)
1 parent 736d613 commit 3fabd54

3 files changed

Lines changed: 36 additions & 26 deletions

File tree

code/common/eodtime.q

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
1-
/ - system eodtime configuartion
2-
/ - loaded into and used in the tp and pdb processes
3-
\d .eodtime
4-
rolltime:@[value;`rolltime;0D00:00:00.000];
5-
datatimezone:@[value;`datatimezone;`$"GMT"];
6-
rolltimezone:@[value;`rolltimezone;`$"GMT"];
7-
dayoffset:@[value;`dayoffset;0];
8-
getdailyadjustment:{first exec adjustment from aj[`timezoneID`gmtDateTime;([]timezoneID:enlist .eodtime.datatimezone;gmtDateTime:enlist .z.p); .tz.t]};
9-
dailyadj:getdailyadjustment[];
10-
adjrolltime:{[p]
11-
z:rolltime - first exec adjustment from aj[`timezoneID`gmtDateTime;([]timezoneID:enlist .eodtime.rolltimezone;gmtDateTime:enlist p); .tz.t];
12-
z:$[z >= 1D;z - 1D;z] // don't let it go past one day
13-
}
14-
getroll:{[p]
15-
z:adjrolltime[p];
16-
("d"$p) + $[z <= p;z+1D;z] // if past time already today, make it tomorrow
17-
}
18-
getday:{[p]
19-
z:adjrolltime[p];
20-
("d"$p) + dayoffset+$[z > p;-1;0] // if not past roll time, subtract one day
21-
}
22-
d:getday[.z.p];
23-
nextroll:getroll[.z.p];
1+
/ - system eodtime configuraion
2+
/ - loaded into and used in the tp and pdb processes
3+
\d .eodtime
4+
5+
// default settings
6+
rolltimeoffset:@[value;`rolltimeoffset;0D00:00:00.000]; // offset from standard midnight rollover
7+
datatimezone:@[value;`datatimezone;`$"GMT"]; // timezone for stamping data
8+
rolltimezone:@[value;`rolltimezone;`$"GMT"]; // timezone for EOD roll
9+
10+
// function to determine offset from UTC for timestamping data
11+
getdailyadjustment:{exec adjustment from .tz.t asof `timezoneID`gmtDateTime!(.eodtime.datatimezone;.z.p)};
12+
13+
dailyadj:getdailyadjustment[]; // get offset when loading process and store it in dailyadj
14+
15+
// function to determine offset from UTC for EOD roll
16+
adjtime:{[p]
17+
:exec adjustment from .tz.t asof `timezoneID`gmtDateTime!(.eodtime.rolltimezone;.z.p);
18+
};
19+
20+
// function to get time (in UTC) of next roll after UTC timestamp, p
21+
getroll:{[p]
22+
z:rolltimeoffset-adjtime[p]; // convert rolltimeoffset from rolltimezone to UTC
23+
z:`timespan$(mod) . "j"$z, 1D; // force time adjust to be between 0D and 1D
24+
("d"$p) + $[z <= p;z+1D;z] // if past time already today, make it tomorrow
25+
};
26+
27+
// function to determine the date (in rolltimezone) from UTC timestamp, p
28+
getday:{[p]
29+
p+:adjtime[p]; // convert date from UTC to rolltimezone
30+
"d"$p-rolltimeoffset // adjust day according to rolltimeoffset
31+
};
32+
33+
d:getday[.z.p]; // get current date when loading process, store in d
34+
nextroll:getroll[.z.p]; // get next roll when loading process, store in nextroll

code/processes/tickerplant.q

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ icounts:()!() / set up dictionary for per table counts
3737
ld:{if[not type key L::`$(-10_string L),string x;.[L;();:;()]];i::j::@[-11!;L;i::-11!(-2;L)];jcounts::icounts;if[0 < type i;-2 (string L)," is a corrupt log. Truncate to length ",(string last i)," and restart";exit 1];hopen L};
3838
tick:{init[];if[not min(`time`sym~2#key flip value@)each t;'`timesym];@[;`sym;`g#]each t;d::.eodtime.d;if[l::count y;L::`$":",y,"/",x,10#".";l::ld d]};
3939

40-
endofday:{end d;d+:1;icounts::()!();.eodtime.nextroll:.eodtime.getroll[.z.p];.eodtime.dailyadj:.eodtime.getdailyadjustment[];if[l;hclose l;l::0(`.u.ld;d)]};
40+
endofday:{end d;d+:1;icounts::()!();if[.z.p>.eodtime.nextroll:.eodtime.getroll[.z.p];system"t 0";'"next roll is in the past"];.eodtime.dailyadj:.eodtime.getdailyadjustment[];if[l;hclose l;l::0(`.u.ld;d)]};
4141
ts:{if[.eodtime.nextroll < x;if[d<("d"$x)-1;system"t 0";'"more than one day?"];endofday[]]};
4242

4343

config/settings/default.q

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ broadcast:1b; // broadcast publishing is on by default. Availb
122122

123123
// timezone
124124
\d .eodtime
125-
rolltime:0D00:00:00.000000000; // time to roll in rolltimezone
125+
rolltimeoffset:0D00:00:00.000000000; // offset from default midnight roll
126126
datatimezone:`$"GMT"; // timezone for TP to timestamp data in
127127
rolltimezone:`$"GMT"; // timezone to perform rollover in
128-
dayoffset:0; // 0 = on rollover, day becomes today; 1 = on rollover, day becomes tomorrow

0 commit comments

Comments
 (0)