ionic-example icon indicating copy to clipboard operation
ionic-example copied to clipboard

Anyone found a way to handle Dates in Ionic production build?

Open dave-ok opened this issue 5 years ago • 5 comments

Please has anyone found a way around the date datatype problem with ionic production builds. I am building an app which is date-centric and this limitation is a downer cos typeorm has everything I need but this. Please help! I need pointers or suggestions

dave-ok avatar Jun 06 '19 18:06 dave-ok

Is handling date as unix time an option?

AchevezAim avatar Jul 15 '19 15:07 AchevezAim

Is handling date as unix time an option?

Pls I dont understand. Can you elaborate?

My question was based on the limitations listed for Ionic production builds where date types are seen as objects and eventually converted to object columns instead of date columns

https://github.com/typeorm/ionic-example/issues/3#issuecomment-348122054

dave-ok avatar Jul 15 '19 17:07 dave-ok

Well, I handle dates as unix time (milliseconds since epoch).

Let's say you have:

export class Thing {
  @PrimaryColumn({ unique: true })
  id: number;
  date: number;
}

When you fetch it, you will get date as number type, you can then use new Date(date*1000)

Or you can make a getter that returns a date object:

export class Thing {
  @PrimaryColumn({ unique: true })
  id: number;
  date: number;

 getDate(): Date{
  return new Date(this.date*1000);
 }
}

It's just a suggestion

AchevezAim avatar Jul 15 '19 22:07 AchevezAim

@AchevezAim Thanks a bunch! Looks like this should work. Date comparison is critical to the project I am working on and with your suggestion I can do just that. I'll get right on it. And thanks again!

dave-ok avatar Jul 16 '19 06:07 dave-ok

@dave-ok Is that working for you? I also like to work on this ORM library and Ionic 4. But not started yet. So how's your experience with this ORM and of course Date manipulation?

Sampath-Lokuge avatar Feb 02 '20 20:02 Sampath-Lokuge