SET_MODTIME set modification time of path

requires: java

function ok = set_modtime(p, t)
arguments
  p (1,1) string
  t (1,1) datetime
end

try
  utc = convertTo(datetime(t, "TimeZone", "UTC"), "posixtime");
catch e
  if strcmp(e.identifier, "Octave:undefined-function")
    utc = t;
  else
    rethrow(e);
  end
end

ok = javaFileObject(p).setLastModified(int64(utc) * 1000);

end

%!test
%! p = tempname();
%! t = time()
%! assert(touch(p, []))
%! assert(set_modtime(p, t))
%! delete(p)