Not sure if I am asking this the right way, but I am building a CRUD
application for a real estate client of mine and everything works as it
should, but I was wondering if there's a way to have Firebase automatically
add a 'creation date' type of object or is this something that needs to be
added from the client side. And if from the client side, what would be the
ideal date format? I need to be able to filter real estate listings in
ng-repeat based on date created. If this makes any sense, I appreciate any
and all feedback.

Thank you for your time.

Chuck

--
You received this message because you are subscribed to the Google Groups "Firebase + AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-angular+unsubscribe@googlegroups.com.
To post to this group, send email to firebase-angular@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-angular/035f2d83-fbd8-4fd5-b161-1084181ca8e9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Jacob Wenger at Oct 22, 2014 at 8:49 pm
    Hey Charles,

    Firebase doesn't natively store JavaScript Date objects. Instead, you have
    two options. One, you could do new Date.getTime() and store that integer
    timestamp in Firebase as you would normally store any data. To get the date
    back, just do new Date(<timestamp>). Second, you could just store new
    Date.toString() and the do new Date(<string>) to get it back out.

    If you use AngularFire's, $FirebaseArray to get an array of listings, you
    should be able to sort via the created_at field. I think you will find that
    the integer timestamp sorts better than the string date, so I would go with
    the first option I mentioned.

    Good luck!
    Jacob
    On Tuesday, October 21, 2014 11:08:15 PM UTC-7, Charles Smith wrote:

    Not sure if I am asking this the right way, but I am building a CRUD
    application for a real estate client of mine and everything works as it
    should, but I was wondering if there's a way to have Firebase automatically
    add a 'creation date' type of object or is this something that needs to be
    added from the client side. And if from the client side, what would be the
    ideal date format? I need to be able to filter real estate listings in
    ng-repeat based on date created. If this makes any sense, I appreciate any
    and all feedback.

    Thank you for your time.

    Chuck
    --
    You received this message because you are subscribed to the Google Groups "Firebase + AngularJS" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to firebase-angular+unsubscribe@googlegroups.com.
    To post to this group, send email to firebase-angular@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-angular/51e0e28d-b950-4b96-b249-d888f35ceeb8%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Victor Mendoza at Oct 23, 2014 at 7:02 pm
    Adding one cent to Jacob´s answer, I am actually applying that method but I
    am using the recommended Firebase time stamp instead of the app time stamp.

    like:
           record.createdAt = Firebase.ServerValue.TIMESTAMP;

    On Wednesday, 22 October 2014 15:49:11 UTC-5, Jacob Wenger wrote:

    Hey Charles,

    Firebase doesn't natively store JavaScript Date objects. Instead, you
    have two options. One, you could do new Date.getTime() and store that
    integer timestamp in Firebase as you would normally store any data. To get
    the date back, just do new Date(<timestamp>). Second, you could just
    store new Date.toString() and the do new Date(<string>) to get it back
    out.

    If you use AngularFire's, $FirebaseArray to get an array of listings, you
    should be able to sort via the created_at field. I think you will find
    that the integer timestamp sorts better than the string date, so I would go
    with the first option I mentioned.

    Good luck!
    Jacob
    On Tuesday, October 21, 2014 11:08:15 PM UTC-7, Charles Smith wrote:

    Not sure if I am asking this the right way, but I am building a CRUD
    application for a real estate client of mine and everything works as it
    should, but I was wondering if there's a way to have Firebase automatically
    add a 'creation date' type of object or is this something that needs to be
    added from the client side. And if from the client side, what would be the
    ideal date format? I need to be able to filter real estate listings in
    ng-repeat based on date created. If this makes any sense, I appreciate any
    and all feedback.

    Thank you for your time.

    Chuck
    --
    You received this message because you are subscribed to the Google Groups "Firebase + AngularJS" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to firebase-angular+unsubscribe@googlegroups.com.
    To post to this group, send email to firebase-angular@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-angular/884d77f1-74b0-4947-a4f7-6927db1a872c%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Thinkerer at Oct 26, 2014 at 12:01 pm
    *I have it in my js controller files as *
    $scope.post = {url: 'http://', title: '', timestamp: new Date()};

    It does appear in my html when i test it with inserting for post, but not
    for posts
         Posts: {{ posts }}
         Post: {{ post }}

    How do I then timestamp each new entry? Am I missing a JS definition? Do I
    need to add?
       var timestamp = new Date().getTime();

    Can someone help with a complete set of codes how the dates are
    implemented? Sorry for the trouble.


    On Wednesday, October 22, 2014 2:08:15 PM UTC+8, Charles Smith wrote:

    Not sure if I am asking this the right way, but I am building a CRUD
    application for a real estate client of mine and everything works as it
    should, but I was wondering if there's a way to have Firebase automatically
    add a 'creation date' type of object or is this something that needs to be
    added from the client side. And if from the client side, what would be the
    ideal date format? I need to be able to filter real estate listings in
    ng-repeat based on date created. If this makes any sense, I appreciate any
    and all feedback.

    Thank you for your time.

    Chuck
    --
    You received this message because you are subscribed to the Google Groups "Firebase + AngularJS" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to firebase-angular+unsubscribe@googlegroups.com.
    To post to this group, send email to firebase-angular@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-angular/421b4198-ff39-4688-b076-37fa8fa9abd2%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Jacob Wenger at Oct 26, 2014 at 5:38 pm
    Hey there,

    The thing to remember here is that storing dates/timestamps is no different
    than storing any other type of data in Firebase. You cannot store arbitrary
    JavaScript objects (like a Date object) in Firebase. So doing:

    ref.set(new Date());

    will not work. Instead, you need to either store it as a string:

    ref.set(new Date().toString());

    or as a number:

    ref.set(new Date().getTime());

    Then you can retrieve that string or number on your client as you normally
    would with any Firebase data. Note that Victor made a great point that it
    is best to use Firebase.ServerValue.TIMESTAMP
    <https://www.firebase.com/docs/web/api/servervalue/timestamp.html> in this
    scenario. It will use the current Firebase server value and help you avoid
    situations where different clients have different clock times. An example
    would look like this:

    $scope.post = { url: 'http://', title: '', timestamp:
    Firebase.ServerValue.TIMESTAMP };

    It's hard for me to give you a full example related to your $scope.posts
    code since I do not know what your code looks like. If you are still having
    issues, please provide a Plunkr, JSFiddler, CodePen, etc. with some code
    that does not work and I can help you debug it.

    Jacob
    On Sat, Oct 25, 2014 at 4:08 AM, Thinkerer wrote:


    *I have it in my js controller files as *
    $scope.post = {url: 'http://', title: '', timestamp: new Date()};

    It does appear in my html when i test it with inserting for post, but not
    for posts
    Posts: {{ posts }}
    Post: {{ post }}

    How do I then timestamp each new entry? Am I missing a JS definition? Do I
    need to add?
    var timestamp = new Date().getTime();

    Can someone help with a complete set of codes how the dates are
    implemented? Sorry for the trouble.


    On Wednesday, October 22, 2014 2:08:15 PM UTC+8, Charles Smith wrote:

    Not sure if I am asking this the right way, but I am building a CRUD
    application for a real estate client of mine and everything works as it
    should, but I was wondering if there's a way to have Firebase automatically
    add a 'creation date' type of object or is this something that needs to be
    added from the client side. And if from the client side, what would be the
    ideal date format? I need to be able to filter real estate listings in
    ng-repeat based on date created. If this makes any sense, I appreciate any
    and all feedback.

    Thank you for your time.

    Chuck
    --
    You received this message because you are subscribed to the Google Groups
    "Firebase + AngularJS" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to firebase-angular+unsubscribe@googlegroups.com.
    To post to this group, send email to firebase-angular@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/firebase-angular/421b4198-ff39-4688-b076-37fa8fa9abd2%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/421b4198-ff39-4688-b076-37fa8fa9abd2%40googlegroups.com?utm_medium=email&utm_source=footer>
    .

    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "Firebase + AngularJS" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to firebase-angular+unsubscribe@googlegroups.com.
    To post to this group, send email to firebase-angular@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-angular/CAKZX5-5TaqjvdE0FRcNOFms4WAT%2B44k_58BbABUThDPi6uFSMg%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupfirebase-angular @
postedOct 22, '14 at 8:07a
activeOct 26, '14 at 5:38p
posts5
users4

People

Translate

site design / logo © 2021 Grokbase