Hi,
I am using GIT_COMMIT_GET function to get the commit date from Github history log. Unfortunately it is giving me a wrong date (10 years old) and when I look at the documentation, this function returns a time starting from 1970:
Time – the number of seconds since January 1st, 1970
As the SAS dates start from 01 Jan 1960, this is giving me a wrong date. Any idea how this can be fixed ?
%let GITBranch=Your_Local_Repository;
data work.x;
format time1 datetime.;
LENGTH COMMIT_ID AUTHOR_NAME AUTHOR_EMAIL MESSAGE PARENT_IDS TIME $ 1024;
N = GIT_COMMIT_LOG("&GITBranch.");
DO I=1 TO N;
RC = GIT_COMMIT_GET(I,"&GITBranch.", "id", COMMIT_ID);
RC = GIT_COMMIT_GET(I,"&GITBranch.", "author", AUTHOR_NAME);
RC = GIT_COMMIT_GET(I,"&GITBranch.", "email", AUTHOR_EMAIL);
RC = GIT_COMMIT_GET(I,"&GITBranch.", "message", MESSAGE);
RC = GIT_COMMIT_GET(I,"&GITBranch.", "parent_ids", PARENT_IDS);
RC = GIT_COMMIT_GET(I,"&GITBranch.", "time", TIME);
Time1=TIME;
output;
END;
RC = GIT_COMMIT_FREE("&GITBranch.");
drop N I RC;
run;
This is not unique to Git -- it's true for any time that you exchange date/time values with a system that uses epoch (Unix-style) times.
Here's an example for how to compensate.
options dlcreatedir;
%let repoPath = %sysfunc(getoption(WORK))/sas-dummy-blog;
libname repo "&repoPath.";
libname repo clear;
/* Fetch latest code from GitHub */
data _null_;
rc = gitfn_clone(
"https://github.com/sascommunities/sas-dummy-blog.git",
"&repoPath.");
put rc=;
run;
data commits (keep=time message);
length time_char $ 100 time 8 message $ 100 n 8;
n = gitfn_commit_log("&repoPath.");
format time datetime20.;
do i=1 to n;
rc = gitfn_commit_get(i,"&repoPath.",'message',message);
rc = gitfn_commit_get(i,"&repoPath.",'time',time_char);
time = trim(time_char);
time = time + "01jan1970 0:0:0"dt;
output;
end;
run;
title "Commits to this sas-dummy-blog repo";
proc print data=commits;
run;
title;
Hmm, this is not a great solution, but you can manually subtract the number of seconds between 01JAN1970 and 01JAN1960 by using the INTCK function:
data A;
adjust = INTCK("seconds", '01JAN1960:00.00.00'dt, '01JAN1970:00.00.00'dt);
put adjust;
run;
The answer is 315,619,200 seconds, so you could adjust the TIME variable in your program by that amount.
This is not unique to Git -- it's true for any time that you exchange date/time values with a system that uses epoch (Unix-style) times.
Here's an example for how to compensate.
options dlcreatedir;
%let repoPath = %sysfunc(getoption(WORK))/sas-dummy-blog;
libname repo "&repoPath.";
libname repo clear;
/* Fetch latest code from GitHub */
data _null_;
rc = gitfn_clone(
"https://github.com/sascommunities/sas-dummy-blog.git",
"&repoPath.");
put rc=;
run;
data commits (keep=time message);
length time_char $ 100 time 8 message $ 100 n 8;
n = gitfn_commit_log("&repoPath.");
format time datetime20.;
do i=1 to n;
rc = gitfn_commit_get(i,"&repoPath.",'message',message);
rc = gitfn_commit_get(i,"&repoPath.",'time',time_char);
time = trim(time_char);
time = time + "01jan1970 0:0:0"dt;
output;
end;
run;
title "Commits to this sas-dummy-blog repo";
proc print data=commits;
run;
title;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: