javascript - Firebase Database Rule that compares timestamp to 00:00:00 of today? - Stack Overflow

I'm trying to create a Firebase Database Rule that forbids users to write to any node which has a

I'm trying to create a Firebase Database Rule that forbids users to write to any node which has a timestamp created before 00:00:00 of today.

Example of database:

{
    "messageID": { 
        "message": "blabla",
        "timestamp": 1481744636
    }
}

Rules:

{
    "rules": {
        "$messageID": {
            ".write": "data.child('timestamp').val() > ???"
        }
    }
}

I know about the 'now' keyword, but I don't think it helps me. I need a way to pare the timestamp with a value for 00:00:00 of today.

I could create and store a table with all the unix epoch times for midnight of each day in the futurem but isn't there a way to calculate it on the fly?

I'm trying to create a Firebase Database Rule that forbids users to write to any node which has a timestamp created before 00:00:00 of today.

Example of database:

{
    "messageID": { 
        "message": "blabla",
        "timestamp": 1481744636
    }
}

Rules:

{
    "rules": {
        "$messageID": {
            ".write": "data.child('timestamp').val() > ???"
        }
    }
}

I know about the 'now' keyword, but I don't think it helps me. I need a way to pare the timestamp with a value for 00:00:00 of today.

I could create and store a table with all the unix epoch times for midnight of each day in the futurem but isn't there a way to calculate it on the fly?

Share Improve this question edited Dec 15, 2016 at 2:12 AL. 37.8k10 gold badges147 silver badges285 bronze badges asked Dec 14, 2016 at 20:38 Dan FlictDan Flict 19911 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

This should do it:

{
    "rules": {
        "$messageID": {
            ".write": "data.child('timestamp').val() > (now - (now % 86400000))"
        }
    }
}

86,400,000 is the number of milliseconds in 24 hours, so now % 86400000 should give you the number of milliseconds since 00:00:00 UTC.

console.log(new Date(Date.now() - (Date.now() % 86400000)))

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745509430a4630702.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信