Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
373 views
in Technique[技术] by (71.8m points)

javascript - 如何在EndTime时间戳之间过滤对象数组StartTime并获取匹配记录(how to filter array of objects StartTime between EndTime timestamp and get match record)

例如我有一个时间startTime 3:30 pm endTime 8:00 pm,并且我有第二个对象startTime 5:30到6:45,这是匹配记录,因为这是在3:30 pm endTime 8:00 pm以下,因此我们将如何计算Java脚本

{"entries":[{"memberId":"5bd06f45607ed03804018267","startTime":1574719200000,"endTime":1574735400000,"description":"Description","issue":"ZFJ-25","issueType":null,"issuePriority":null,"issueStatus":null,"issueSummary":"isues tect","projectKey":"ZFJ","projectName":"ZFJ","worklogId":"10299","epicKey":null,"accountKey":null,"componentKey":[],"fixVersion":null,"subTask":[],"sprint":null,"issueReporter":null,"role":null,"planned":false,"locked":true,"approvalId":"5bd06f45607ed0380401826720193023","timeSpent":"16200","mirhaiTask":null,"clientKey":"56583e1e-00d6-3794-aa29-408e43ec2bff","id":"5bd06f45607ed038040182671574836779805"},{"memberId":"5bd06f45607ed03804018267","startTime":1574725545000,"endTime":1574730045000,"description":"Description","issue":"ZFJ-24","issueType":null,"issuePriority":null,"issueStatus":null,"issueSummary":"some issue","projectKey":"ZFJ","projectName":"ZFJ","worklogId":"10298","epicKey":null,"accountKey":null,"componentKey":[],"fixVersion":null,"subTask":[],"sprint":null,"issueReporter":null,"role":null,"planned":false,"locked":true,"approvalId":"5bd06f45607ed0380401826720193023","timeSpent":"4500","mirhaiTask":null,"clientKey":"56583e1e-00d6-3794-aa29-408e43ec2bff","id":"5bd06f45607ed038040182671574836752275"},{"memberId":"5bd06f45607ed03804018267","startTime":1574736300000,"endTime":1574747100000,"description":"mqbsqnm","issue":"ZFJ-32","issueType":null,"issuePriority":null,"issueStatus":null,"issueSummary":"abcd","projectKey":"ZFJ","projectName":"ZFJ","worklogId":"10303","epicKey":null,"accountKey":null,"componentKey":[],"fixVersion":null,"subTask":[],"sprint":null,"issueReporter":null,"role":null,"planned":false,"locked":true,"approvalId":"5bd06f45607ed0380401826720193023","timeSpent":"10800","mirhaiTask":null,"clientKey":"56583e1e-00d6-3794-aa29-408e43ec2bff","id":"5bd06f45607ed038040182671575023958801"},{"memberId":"5bd06f45607ed03804018267","startTime":1574756100000,"endTime":1574766900000,"description":"dss","issue":"ZFJ-30","issueType":null,"issuePriority":null,"issueStatus":null,"issueSummary":"HI","projectKey":"ZFJ","projectName":"ZFJ","worklogId":"10305","epicKey":null,"accountKey":null,"componentKey":[],"fixVersion":null,"subTask":[],"sprint":null,"issueReporter":null,"role":null,"planned":false,"locked":true,"approvalId":null,"timeSpent":"10800","mirhaiTask":null,"clientKey":"56583e1e-00d6-3794-aa29-408e43ec2bff","id":"5bd06f45607ed038040182671575189847753"}],"memberId":"5bd06f45607ed03804018267","totalHours":11,"numIssues":4,"status":"APPROVED"}
  ask by vinod joshi translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use the filter() method:

(使用filter()方法:)

var startTime = 1575158418000;
var endTime = 1575244758000;

var entries = [
  {
    startTime: 1575190818000,
    endTime: 1575212418000
  },
  {
    startTime: 1575277218000,
    endTime: 1575284418000
  }
];

var matchingEntries = entries.filter(entry =>
  entry.startTime >= startTime && entry.endTime <= endTime);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...