Date and Calendar Analytics
wknd_date.cpp

This is an example program how to call the SFDB_WKNDate API More details about this example.

Note
The example here references two functions defined in dbm_init.cpp file:
  • dbm_example_init
  • dbm_example_shutdown
#include <windows.h>
#include <iostream>
#include <string>
#include "SFLOG.h"
#include "SFDBM.h"
bool dbm_example_init(void);
void dbm_example_shutdown(void);
int main(){
// initialize the logging, licesne and then the calendar module here ..
if(!dbm_example_init()){
std::wcout << L" ERROR - Failed to initialize the sdk. Exit!" << std::endl;
return -1;
}
long dt = 41030; // Tuesday May 1, 2012
std::wstring szHolidays;
WORD wkndNo = 1; // (Saturday, Sunday) wkncode: 0000011
WORD wkdOption = 1; // (1 = all (default), 2 = ignore holidays, 3 = only short weekends, 4 = only long weekends).
WORD direction = 1; // (1 = next weekend(default), 2 = last weekend).
long lNextWknd = 0;
// Next weekend
int nRetCode = SFDB_WKNDate(dt, NULL, NULL, 0, wkndNo, wkdOption, direction, &lNextWknd); //lNextWknd == 41034 (Saturday)
if(nRetCode == NDK_SUCCESS){
std::wcout << L" SUCCESS - SFDB_WKNDate for next weekend: " << lNextWknd << std::endl;
// calculate duration of this weekend
WORD wDur=0;
nRetCode = SFDB_WKNDur (lNextWknd, NULL, NULL, 0, wkndNo, &wDur); // wDur == 2
if(nRetCode == NDK_SUCCESS){
std::wcout << L" SUCCESS - the duration SFDB_WKNDur for a given weekend: " << wDur << std::endl;
}
}
// Previous weekend
direction = 2;
long lPrevWknd = 0;
nRetCode = SFDB_WKNDate(dt, NULL, NULL, 0, wkndNo, wkdOption, direction, &lPrevWknd); // lPrevWknd == 41028 (Sunday)
if(nRetCode == NDK_SUCCESS){
std::wcout << L" SUCCESS - SFDB_WKNDate for last weekend: " << lPrevWknd << std::endl;
}
// shutdown the calendar, license and logging module here.
dbm_example_shutdown();
return 0;
}
#define NDK_SUCCESS
int __stdcall SFDB_WKNDur(LONG argDate, LPCTSTR holidays, LPLONG zDates, size_t nSize, WORD nWkndNo, LPWORD retVal)
Calculate the duration in calendar days of the long weekend that a given date falls on.
Definition weekend.cpp:464
int __stdcall SFDB_WKNDate(LONG argDate, LPCTSTR holidays, LPLONG zDates, size_t nSize, WORD nWkndNo, WORD argLWkndOption, WORD argDirection, LPLONG retVal)
Calculate the serial date number for the first day of the next weekend (or the last day of the last w...
Definition weekend.cpp:575