0

I am thinkink how to generate data structure representing tasks in my calendar (for my private purposes only). I have date-ordered tasks records from DBMS like these:

Buy milk (on 18.1.2013)

  • task date (2013-01-15)
  • task label ("Buy milk")
  • time frame ("day")

or

Task: Wash a car (sometime in January 2013)

  • task date (2013-01-05)
  • task label ("Wash a car")
  • time frame ("month")

"time frame" value is enum value {DAY,WEEK,MONTH,QUARTER,YEAR} and specifies time frame of the task, e.g. time frame "month" specifies that this task needs to be done sometime in month specified by task date value.

I would like to represent my tasks in date structure, e.g.:

  • 2013 (year)
  • I. (quarter)
  • January (month)
  • Wash a car
  • Week 14.1.-20.1.
  • 15.1.2013 (day)
  • Buy milk
  • 18.1.2013 (day)
  • Do somenthing...

etc. It is not problem but problem occures when there is record from next data frame, e.g. task from February.

I have tried many ways how to accomplish it but the my biggest problem is to select proper data structure and find algorithm how to fill into my structure all data frames values above concrete task and how to don't do it when these data frames exist.

I hope I explained it clearly. Thank you for ideas.

4

1 回答 1

1

听起来您可以将其归结为标签和开始+结束时间。与其用天、周、月、季度和年来解决问题,不如直接使用日期戳?可以使用标准库将它们转换为日期、时间和 UNIX 时间戳(自 1970 年 1 月 1 日以来的秒数)。还有为多种语言编写的日期计算库(例如 date+1week)。

编辑:或者,您当然也可以保留开始日期和持续时间(可能最简单的以秒为单位)而不是结束日期。每种表示方式都有其优点和缺点。

于 2013-01-18T14:59:20.093 回答