Code Monkey home page Code Monkey logo

Comments (12)

mizzao avatar mizzao commented on May 22, 2024

How would it be any different than doing the following?

{'status.lastLogin': {$gte: Date.now() }}

I thought about this, but I couldn't see any difference in storing things as native Date objects.

from meteor-user-status.

geekyme avatar geekyme commented on May 22, 2024

Technically results can still be the same, there's a discussion thread on meteor-talk too regarding this topic that I participated in. The guys recommended the native Dates too. https://groups.google.com/forum/#!searchin/meteor-talk/storing$20date/meteor-talk/jujlCBRI4X0/vgWJlgp5MEUJ

from meteor-user-status.

mizzao avatar mizzao commented on May 22, 2024

Okay, I'm listening. How do comparisons between native Date objects work? Do they still work between different timezones? What is the purpose of the timezone that is stored in the native date?

Why does one person say to store the timezone separately while the other person says the timezone is included in ISODate?

The other reason I decided to stick with integers is because of the time offset calculated by timesync. I wasn't sure how to do these diff operations with regular dates and it seemed that instantiating new dates constantly (because of the reactive time variables) would be much more inefficient than necessary. Any comments about that?

from meteor-user-status.

geekyme avatar geekyme commented on May 22, 2024

One benefit I see so far in the use of storing native dates is its auto conversion to the right timezone on the client side.

So on my meteor server it records as UTC. But when I load my page in Singapore and retrieve the date field stored, it accurately logs as GMT+8 Singapore time.

from meteor-user-status.

geekyme avatar geekyme commented on May 22, 2024

Oh and regarding the comment about storing timezone separately I think that's not required. As mentioned above all the dates in the meteor server just need to be stored in UTC. I think by default the *.meteor.com servers I'm using are already preconfigured to output UTC time when you do new Date() on the server side.

from meteor-user-status.

mizzao avatar mizzao commented on May 22, 2024

I thought the conversion to the correct timezone is determined by the browser. If I load up the timestamp in a browser as new Date(timestamp) it will display in local time, no problem.

If there is no need to store the timezone in the ISO Date then it doesn't seem to confer any benefits to using it (other than the mongo aggregation queries in the thread you linked.) The only other benefit that I see is you would get to store the timezone of client-generated timestamps, but that seems like an edge case.

from meteor-user-status.

geekyme avatar geekyme commented on May 22, 2024

true. well just a suggestion. cheers.

from meteor-user-status.

mizzao avatar mizzao commented on May 22, 2024

We can leave this open and see if anyone else wants to chime in about it. I'm open to the idea.

In my use cases the integer is far more convenient than the dates because I am measuring time differences and don't want to be using Date objects or moment computations unnecessarily. But I'm interested in hearing other use cases.

from meteor-user-status.

geekyme avatar geekyme commented on May 22, 2024

ok cool thanks!

from meteor-user-status.

wraybowling avatar wraybowling commented on May 22, 2024

It's always smart to store dates as Date objects. You can always use valueOf() to get the epoch back out and do the same math you're doing now, but when someone calls the value out, it won't just be an integer. It will be a date object. And that's more human, and thus what I think should be done. I agree with @geekyme

from meteor-user-status.

mizzao avatar mizzao commented on May 22, 2024

Hi @wraybowling, thanks for pitching in. I don't think anything you said points to an explicit benefit of using Date objects versus integers, but I'll keep it in mind. I don't see any method as being 'more human' than the other, though.

from meteor-user-status.

mizzao avatar mizzao commented on May 22, 2024

Hi @geekyme, new timestamps stored in the database are all native Date objects now. Let me know if you find any issues in this version.

Old timestamps are not automatically converted; you may want to do that yourself, but I'm not sure it matters because most libraries that use dates accept integers or native Dates interchangeably.

from meteor-user-status.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.