ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
[R] has joined #crystal-lang
ur5us__ has quit [Ping timeout: 272 seconds]
ur5us__ has joined #crystal-lang
ur5us__ has quit [Ping timeout: 250 seconds]
ur5us__ has joined #crystal-lang
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
<FromGitter> <manveru:matrix.org> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=610a739a3eec6d41d13aebe3]
<FromGitter> <manveru:matrix.org> i think this should be in stdlib :)
<FromGitter> <manveru:matrix.org> not sure if Int64 is a good input type though...
ur5us__ has quit [Ping timeout: 240 seconds]
<straight-shoota> @manuveru your f is value is `1e10`, but it should probably be `1e9` for the number of nanoseconds per second.
<FromGitter> <manveru:matrix.org> @straight-shoota: sorry, i copied it wrong once, disregard that :)
<FromGitter> <manveru:matrix.org> still think there's no good way of achieving this without monkey-patching Time
<FromGitter> <manveru:matrix.org> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=610a7c7f4b7707158f648a2c]
<FromGitter> <manveru:matrix.org> in case someone looks for this in future
<straight-shoota> See https://crystal-lang.org/api/1.1.1/Time.html#utc(*,seconds:Int64,nanoseconds:Int32):Time-class-method for the semantics of the seconds parameter
<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
<FromGitter> <Blacksmoke16> rip
<raz> starts_with/ends_with to the rescue
<raz> ha, it works!
<riza> https://carc.in/#/r/bpez whhhaaaaaaat am i missing here
<riza> raz: such macro -- that's 4 levels deep for-loops
<riza> > Object.all_subclasses
<riza> oh I have a spare builder.object in there... the hash does it's own builder.object
<raz> yup, compiler was convinced he couldn't do it. no self-esteem that poor thing.
<raz> eh yea... the builder... that one throws me off every time too
<raz> nesting that correctly is a science of its own
dostoyevsky2 has joined #crystal-lang
ur5us__ has joined #crystal-lang
<riza> https://carc.in/#/r/bpfq I'll admit I didn't expect that
<riza> I'm not really sure I understand why those decisions were made
ur5us__ has quit [Ping timeout: 240 seconds]
ur5us__ has joined #crystal-lang