ChanServ changed the topic of #crystal-lang to: The Crystal programming language | | Fund Crystal's development: | GH: | Docs: | Gitter:
[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> <> 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> <> 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> <> 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> <> for some reason Time#total_seconds is a private method, so i cannot use `Time::UNIX_EPOCH.total_seconds` either
<FromGitter> <> and of course the constructor with `unsafe_utc_seconds` is protected too, so i cannot construct my own either
<FromGitter> <> ```code paste, see link``` []
<FromGitter> <> i think this should be in stdlib :)
<FromGitter> <> 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> <> @straight-shoota: sorry, i copied it wrong once, disregard that :)
<FromGitter> <> still think there's no good way of achieving this without monkey-patching Time
<FromGitter> <> ```code paste, see link``` []
<FromGitter> <> in case someone looks for this in future
<straight-shoota> See*,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> <> yeah... i haven't really encountered them much outside of the HashiCorp Nomad APIs
<FromGitter> <> 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 =~ /Foo::.*Request/` and starts patching up things. inside that if-block i need to grab the enum values from `Foo::#{}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 =~ /#{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> 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> 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