vogels icon indicating copy to clipboard operation
vogels copied to clipboard

schema.timestamp flexibility

Open Incubatio opened this issue 9 years ago • 6 comments

Would be nice to be able to be able to customize createdAt and updatedAt format simply.

The point being to allow user to choose their format according to their need knowing that numeric has faster comparison and better compression and String is usually more readable (if using decent formatting like ISOString).

current definition is:

timestamp: true

we could keep the true with it default toISOString() behavior, and add possibility to define a function:

timestamp: function(date) {
  // return desired format
  return date.toISOString(); // timezone, current default
}

Here is a list of example:

  return date.getTime(); // timestamp in ms
  return date.getTime() / 1000; // timestamp in s
  return parseInt(d.toISOString().split('T')[0].replace(/-/g, '')); // readable int, yyyymmdd
  // etc ...

Incubatio avatar Oct 31 '15 12:10 Incubatio

With this commit you can change the schema property from timestamps: true, to:

timestamps: function () {
    return Date.now();
}, 

or something like:

timestamps: function () {
    return Math.floor(Date.now() / 1000);
}, 

set-killer avatar Nov 13 '15 16:11 set-killer

Does it also work for 'updatedAt' ?

osi-bhushankumar avatar Jun 10 '16 14:06 osi-bhushankumar

@osi-bhushankumar: Yes.

set-killer avatar Jun 10 '16 15:06 set-killer

@Incubatio please, don't close this issue. It is not merged yet. Pull Request #99

set-killer avatar Jun 10 '16 15:06 set-killer

@ryanfitz Any idea when we can have a similar feature officially supported?

sohailalam2 avatar Aug 14 '18 08:08 sohailalam2

This project is not maintained. The last commits are from Jan 13, 2016. @ryanfitz is nowhere to be found.

You can checkout the projects Dynogels (fork of Vogels) or Dynamoose.

set-killer avatar Aug 16 '18 19:08 set-killer