Hacker Newsnew | past | comments | ask | show | jobs | submit | nalgeon's commentslogin

The title of the article is "Micro-libraries need to die already". Renaming the submission to "Micro-libraries should never be used" is pathetic, Daniel. I'm not surprised though.


Thanks for the suggestion! True, only fixed offsets are supported, not timezone names.


@nalgeon

Do you plan to address the use cases in the SO post, or asked differently - what is the intended use case of this library?

I tried to recreate it on your site (which is very cool btw in allowing the code to run in browser) and it seems to fail and give the wrong time difference.

  select time_compare(time_date(1927, 12, 31, 23, 58, 08, 0, 28800000), time_date(1927, 12, 31, 23, 58, 09, 0, 28800000));
Results in an answer of '1', which is incorrect.

Please don't take my comments as being negative or unappreciated, this is super difficult stuff and anyone who tries to make the world an easier place should be thanked for that. So thank you.

----

EDIT: this post explains why the answer isn't "1"

https://stackoverflow.com/questions/6841333/why-is-subtracti...


I appreciate your comments, and thank you for trying out the extension.

This query returns -1 (minus one, not one), which seems correct to me. The first date is before the second:

    select time_compare(
      time_date(1927, 12, 31, 23, 58, 08, 0, 28800000),
      time_date(1927, 12, 31, 23, 58, 09, 0, 28800000)
    );

    -1


As discussed in the top-level comment, this library has no concept of timezones (only offsets) so the SO link does not apply. The time rollback only happened in Asia/Shanghai.


Storing unix timestamp as nanoseconds is not Go's style, but you can do just that with this extension.

    select time_to_nano(time_now());
    -- 1722979335431295000


> If the result exceeds the maximum value that can be stored in a Duration, the maximum duration will be returned.


It works very well for me and thousands of other Go developers. That's why I chose this approach.


There's no reason it wouldn't "work", the question is "why". Having such precise dates obviously comes with some compromises (e.g., the representation is larger, or it's variable depending on the value which comes with additional complexity, etc.). So surely there must be some pros to counterbalance the cons. "Because it's what Go does" is an answer, but I don't know if it's a convincing one.


[flagged]


WTF. I'm interested in what you've created and want to understand the reason for your design decisions, and this is how you reply?

edit: Well, it seems that the parent comment has been edited. But honestly, after reading the initial comment, I'm not interested in engaging in any way whatsoever with this person.


There's nothing in the linked blog post justifying why you might want a higher precision time. In fact the blog post would benefit from an explanation that outlines the current datetimes in sqlite and why they're insufficient.


Internally, SQLite uses milliseconds since the Julian day epoch stored as an 64-bit integer for date math, and uses the proleptic gregorian calendar (no leap seconds).

Externally, it uses either (a subset of) ISO 8601 with millisecond precision for a textual representation, or a IEEE 64-bit float representing either days since the Julian day epoch, or seconds since the Unix epoch.

You can also use integer seconds since the Unix epoch, but you'll get outside the supported date range before you use 53-bits, so 64-bit floats are equally safe.

The supported date range, btw., is from JDN zero through 9999-12-31T23:59:59.999.

In the 21st century, both of these representations can store the correctly rounded millisecond.

SQLite accepts time zone offsets, but immediately converts all times to UTC (or local time) and does not store the offset, so date functions can only output UTC or local time (no other time zone or offset).


I think you're being overly defensive. The GP is curious about the decisions you made, and just asking questions in a bit of a blunt (but not rude or accusatory) style that's typical for HN.

edit: the comment I'm responding to was much more vitriolic, it's since been edited


Nice. Smoking cigarettes works for me and millions of others but it's still stupid and will take years or decades of your life.


If you find the official release notes a bit dry (they really are), I've prepared an interactive version with lots of examples:

- Iterators (range / types / pull / slices / maps).

- Timer changes (garbage collection and reset/stop behavior).

- Canonical values with the `unique` package.

- HTTP cookie handling.

- Copying directories.

- Slices and atomics changes.

https://antonz.org/go-1-23


Thank you for your service, this is awesome! I'd love to see language maintainers post interactive release notes like this.


I want to understand the purpose of maps.All().

In the example:

  m := map[string]int{"a": 1, "b": 2, "c": 3}
  
  for k, v := range maps.All(m) {
   fmt.Printf("%v:%v ", k, v)
  }
  
  fmt.Println("")
  
  for k, v := range m {
   fmt.Printf("%v:%v ", k, v)
  }
These both output the same thing. What's the point of the addition?

Slices.All() seems similarly redundant and pointless.

Surely I must be misunderstanding something, I hope.


They’re useful because they let you pass a slice or map to something built to handle the new func(func (…) bool) style iterators.

If I create a IterateOver(fn func(func (K, V any) bool)) function, you cannot pass a slice since that doesn’t match fn’s type, but if you wrap it with slices.All it’ll work.


You can use it with other functions that use iterators. For example, here is code that makes a copy of a map keeping only the even keys.

  maps.Collect(xiter.Filter2(func(k, v int) bool { return k%2 == 0 }, maps.All(m)))


This is great, thank you.


Thank you, glad you like it! In fact, one of the reasons I started Codapi in 2023 was to have a playground for an interactive book on Go concurrency.

I got a bit carried away with Codapi and later Redka (Redis+SQLite), but eventually returned to the book :)


Context in Go is (mostly) a tool for canceling operations. There will be a chapter on contexts in part 1 of the book.


Ahem. Thanks


Educative also has a very strange (to say the least) way of interacting with authors: https://antonz.org/educative


Codapi works with mkdocs (and basically any other static generator).

Here is the JS widget and integration guides:

https://github.com/nalgeon/codapi-js


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: