使用javascript中的日期格式将主题对象与开始日期和结束日期分开

时间:2018-05-27 08:22:13

标签: javascript angularjs lodash

模块具有某些主题,其中包含开始日期和结束日期。这些主题将在每天分开,这意味着所有主题将在同一天进行。主题可以在一天内完成,可以在一天内完成,也可以在一天内涵盖多个主题。以下是示例数据。什么是最好的算法来显示所有主题将在日常覆盖。

对于样本json,输出应为:

    [  
       {  
       "day":"Day 1",
       "topics":[  
       "Module 1 Topic 1"
       ]
       },
       {  
       "day":"Day 2",
       "topics":[  
       "Module 1 Topic 2"
       ]
       },
       {  
       "day":"Day 3",
       "topics":[  
       "Module 2 Topic 1"
       ]
       },
       {  
       "day":"Day 4",
       "topics":[  
       "Module 2 Topic 1",
       "Module 2 Topic 2"
       ]
       },
       {  
       "day":"Day 5",
       "topics":[  
       "Module 2 Topic 2",
       "Module 2 Topic 3"
       ]
       },
       {  
       "day":"Day 6",
       "topics":[  
       "Module 3 Topic 1",
       "Module 4 Topic 1",
       "Module 5 Topic 1"
       ]
       },
       {  
       "day":"Day 7",
       "topics":[  
       "Module 6 Topic 1"
       ]
       }
    ]

示例MongoDB快照:

    "MODULES_ASSOCIATED" : [ 
        {
            "NAME" : "Module 1",
            "_id" : "5a28e7ea84b3cd7904f70437",
            "TOPICS_ASSOCIATED" : [ 
                {
                    "NAME" : "Module 1 Topic 1",
                    "_id" : "5a28e7e184b3cd7904f6f811",
                    "END_DATE" : ISODate("2018-05-25T14:35:00.000Z"),
                    "START_DATE" : ISODate("2018-05-25T14:35:00.000Z")
                }, 
                {
                    "NAME" : "Module 1 Topic 2",
                    "_id" : "5a28e7e284b3cd7904f6fb32",
                    "END_DATE" : ISODate("2018-05-28T14:35:00.000Z"),
                    "START_DATE" : ISODate("2018-05-28T14:35:00.000Z")
                }
            ]
        }, 
        {
            "NAME" : "Module 2",
            "_id" : "5a28e7eb84b3cd7904f7048f",
            "TOPICS_ASSOCIATED" : [ 
                {
                    "NAME" : "Module 2 Topic 1",
                    "_id" : "5a28e7e184b3cd7904f6f817",
                    "END_DATE" : ISODate("2018-05-30T14:35:00.000Z"),
                    "START_DATE" : ISODate("2018-05-29T14:35:00.000Z")
                }, 
                {
                    "NAME" : "Module 2 Topic 2",
                    "_id" : "5a28e7e284b3cd7904f6fb76",
                    "END_DATE" : ISODate("2018-05-31T14:36:00.000Z"),
                    "START_DATE" : ISODate("2018-05-30T14:36:00.000Z")
                }, 
                {
                    "NAME" : "Module 2 Topic 3",
                    "_id" : "5a28e7e284b3cd7904f6fb12",
                    "END_DATE" : ISODate("2018-05-31T14:37:00.000Z"),
                    "START_DATE" : ISODate("2018-05-31T14:37:00.000Z")
                }
            ]
        }, 
        {
            "NAME" : "Module 3",
            "_id" : "5a28e7eb84b3cd7904f70490",
            "TOPICS_ASSOCIATED" : [ 
                {
                    "NAME" : "Module 3 Topic 1",
                    "_id" : "5a28e7e284b3cd7904f6fbb7",
                    "END_DATE" : ISODate("2018-06-01T14:39:00.000Z"),
                    "START_DATE" : ISODate("2018-06-01T14:38:00.000Z")
                }
            ]
        }, 
        {
            "NAME" : "Module 4",
            "_id" : "5a28e7eb84b3cd7904f70488",
            "TOPICS_ASSOCIATED" : [ 
                {
                    "NAME" : "Module 4 Topic 1",
                    "_id" : "5a28e7e284b3cd7904f6fbb8",
                    "END_DATE" : ISODate("2018-06-01T14:40:00.000Z"),
                    "START_DATE" : ISODate("2018-06-01T14:40:00.000Z")
                }
            ]
        }, 
        {
            "NAME" : "Module 5",
            "_id" : "5a28e7eb84b3cd7904f70480",
            "TOPICS_ASSOCIATED" : [ 
                {
                    "NAME" : "Module 5 Topic 1",
                    "_id" : "5a28e7e284b3cd7904f6fba3",
                    "END_DATE" : ISODate("2018-06-01T14:40:00.000Z"),
                    "START_DATE" : ISODate("2018-06-01T14:40:00.000Z")
                }
            ]
        }, 
        {
            "NAME" : "Module 6",
            "_id" : "5a28e7eb84b3cd7904f70493",
            "TOPICS_ASSOCIATED" : [ 
                {
                    "NAME" : "Module 6 Topic 1",
                    "_id" : "5a28e7e284b3cd7904f6fb45",
                    "END_DATE" : ISODate("2018-06-04T14:40:00.000Z"),
                    "START_DATE" : ISODate("2018-06-04T14:40:00.000Z")
                }
            ]
        }
    ]

0 个答案:

没有答案