values = {1, 60, 60, 24, 30, 12};
names = {"second", "minute", "hour", "day", "month", "year"};
Do[values[[i]] *= values[[i - 1]], {i, 2, Length@values}]
(unit[#[[1]]] = #[[2]]) & /@ Partition[Riffle[names, values], 2];
(position[#[[1]]] = #[[2]]) & /@ Partition[Riffle[names, Range[Length@names]], 2];
h[ds_] := Module[
{r},
r = StringJoin[
Reverse@MapIndexed[
If[#1 > 0, ToString@#1 <> " " <> names[[#2]] <> If[#1 > 1, "s ", " "], ""] &,
ds]
];
If[r != "", StringDrop[r, -1], ""]
];
f[t_, u_: 0, z_: {}] := If[u == 0,
z,
f[Mod[t, values[[u]]], u - 1, Prepend[z, Quotient[t, values[[u]]]]]
];
g[s_] := With[
{tokens = StringSplit[s]},
f[ToExpression[tokens[[1]]] unit[StringDrop[tokens[[2]], -1]], position[StringDrop[tokens[[4]], -2]]]
];
is = {"1000000 days in years?", "33 hours in months?", "0 seconds in years?", "1 years in years?", "9876543210 seconds in years?"};
g /@ is
h /@ g /@ is
{{0, 0, 0, 10, 9, 2777}, {0, 0, 9, 1, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 1}, {30, 13, 20, 11, 6, 317}}
{"2777 years 9 months 10 days", "1 day 9 hours", "", "1 year", "317 years 6 months 11 days 20 hours 13 minutes 30 seconds"}