I'm pretty sure this will provide the desired semantics, though I am away from a usable postgres and not bothering to test it.
CREATE FUNCTION date_diff(granularity text, t1 timestamptz, t2 timestamptz) RETURNS int8 AS $$
SELECT date_part(granularity, date_trunc(granularity, t2) - date_trunc(granularity, t1))::int8
$$ LANGUAGE SQL;