mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-03 03:15:31 -04:00
Merge pull request #57 from hkalexling/feature/home-ctime
Add `ctime` helper function
This commit is contained in:
commit
1cb470fb2d
13
src/util.cr
13
src/util.cr
@ -99,3 +99,16 @@ end
|
|||||||
def random_str
|
def random_str
|
||||||
UUID.random.to_s.gsub "-", ""
|
UUID.random.to_s.gsub "-", ""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Works in all Unix systems. Follows https://github.com/crystal-lang/crystal/
|
||||||
|
# blob/master/src/crystal/system/unix/file_info.cr#L42-L48
|
||||||
|
def ctime(file_path : String) : Time
|
||||||
|
res = LibC.stat(file_path, out stat)
|
||||||
|
raise "Unable to get ctime of file #{file_path}" if res != 0
|
||||||
|
|
||||||
|
{% if flag?(:darwin) %}
|
||||||
|
Time.new stat.st_ctimespec, Time::Location::UTC
|
||||||
|
{% else %}
|
||||||
|
Time.new stat.st_ctim, Time::Location::UTC
|
||||||
|
{% end %}
|
||||||
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user