Sam covers this in the Time-Intelligence Mini-Series module. You cannot use the built in time intelligence functions and need to have a detailed Calendar table and then you can explicitly write out the function, but the the module covers all of that.