ur5us__ has quit [Remote host closed the connection]
ur5us__ has joined #crystal-lang
notzmv has quit [Read error: Connection reset by peer]
ur5us__ has quit [Ping timeout: 240 seconds]
ur5us__ has joined #crystal-lang
ur5us__ has quit [Ping timeout: 256 seconds]
notzmv has joined #crystal-lang
<FromGitter>
<manveru:matrix.org> i'm having a bit of trouble with the Time API... trying to convert a unix time in nanoseconds into a Time instance seems to be kinda strange
<FromGitter>
<manveru:matrix.org> i assumed `ns = 1628066435478994700; f = 10000000000; pp! Time.utc(seconds: (ns / f).to_i64, nanoseconds: (ns % f).to_i32)` would do the trick, but it gives me an arithmatic overflow
<FromGitter>
<manveru:matrix.org> also, `ns = 1628066435478994700; f = 1000000000; pp! Time.utc(seconds: (ns / f).to_i64, nanoseconds: 0)` gives me a time in the year 52... so i guess i have to add 1970 years to that?
ur5us__ has joined #crystal-lang
<FromGitter>
<manveru:matrix.org> for some reason Time#total_seconds is a private method, so i cannot use `Time::UNIX_EPOCH.total_seconds` either
<FromGitter>
<manveru:matrix.org> and of course the constructor with `unsafe_utc_seconds` is protected too, so i cannot construct my own either
<straight-shoota>
Yeah, there's currently no nanosecond support in the unix constructor. I think we could add an additional paramter to Time.unix
<straight-shoota>
You can reach the same with `Time.unix((ns / f).to_i64).shift(nanoseconds: (ns % f).to_i32)` though
<straight-shoota>
unix_ns might also be a nice addition to stdlib, but it seems nobody has asked for that yet. I don't think 64-bit nanosecond timestamps are very common.
<FromGitter>
<manveru:matrix.org> yeah... i haven't really encountered them much outside of the HashiCorp Nomad APIs
<FromGitter>
<manveru:matrix.org> well, and Loki timestamps
dostoyevsky2 has quit [Ping timeout: 240 seconds]
<raz>
`{% for klass in "Foo::Bar".subclasses %}`
<raz>
is there a way to resolve to a class from a string literal in a macro
<FromGitter>
<Blacksmoke16> why not just do `Foo::Bar` if it's a static string?
<raz>
well it isn't, that's why i'm asking ;)
<raz>
it's more like `{% for class in "#{foo}::Bar" %}`
<FromGitter>
<Blacksmoke16> and im assuming `foo` is a macro arg?
<raz>
a var in the macro context yea
<FromGitter>
<Blacksmoke16> hmm
<raz>
only way i've found so far is to iterate over everything with `{% for klass in Object.all_subclasses %}` and then pick out the one i want with a regex match
<raz>
but that feels... not quite right
<FromGitter>
<Blacksmoke16> yea idt there's an easy way
<FromGitter>
<Blacksmoke16> what are you wanting to do?
<raz>
well, it's nested and complicated... ;) essentially i *am* in a loop like the above that iterates over all classes and then does `if klass.name.id =~ /Foo::.*Request/` and starts patching up things. inside that if-block i need to grab the enum values from `Foo::#{klass.id}Error` to generate methods for them (related to the problem from the other day, no way to pass symbols around sadly)
<raz>
i mean it should be doable by starting another iteration over the universe as outlined above. it just already feels kinda outlandish. feels like there should be a more straightforward way
<FromGitter>
<Blacksmoke16> nope
<FromGitter>
<Blacksmoke16> just will have to loop a few times, thats the only way you can get a `TypeNode` is from one of those iterating methods, a hardcoded type, or `@type`
<raz>
oki doki. then we'll do another pass over everything. o/
<raz>
ouchi
<raz>
`{% if klass.name.id =~ /#{pkg}::#{op}Error$/ %}` - Error: regex interpolations not yet allowed in macros