Let's number the scale steps of the major scale $1,2,\ldots 7$, i.e., label them from the tonic upward mod $7$ and then add $1$. With that numbering scheme, let the lowest note of a given diatonic interval be $x$ and the highest note $y$. 

Is there an "easy" or at least "manageable" formula/algorithm for the function $I(x,y)$, where $I$ takes values $1,2,\ldots,7$ according as the interval between $x$ and $y$ is a unison, second, third, etc.?

For example, $I(6,4)=6$. 

As a further question, could we then modify the formula for $I(x,y)$ into one for $J(x,y)$, where $J(x,y)=(I(x,y),Q)$, with $Q$ the quality (major, minor, perfect, augmented, diminished) of the interval according to some convenient numerical labeling?