OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 21 matching lines...) Expand all Loading... |
32 #define DateComponents_h | 32 #define DateComponents_h |
33 | 33 |
34 #include "platform/PlatformExport.h" | 34 #include "platform/PlatformExport.h" |
35 #include "wtf/Allocator.h" | 35 #include "wtf/Allocator.h" |
36 #include "wtf/Forward.h" | 36 #include "wtf/Forward.h" |
37 #include "wtf/text/Unicode.h" | 37 #include "wtf/text/Unicode.h" |
38 #include <limits> | 38 #include <limits> |
39 | 39 |
40 namespace blink { | 40 namespace blink { |
41 | 41 |
42 // A DateComponents instance represents one of the following date and time combi
nations: | 42 // A DateComponents instance represents one of the following date and time |
| 43 // combinations: |
43 // * Month type: year-month | 44 // * Month type: year-month |
44 // * Date type: year-month-day | 45 // * Date type: year-month-day |
45 // * Week type: year-week | 46 // * Week type: year-week |
46 // * Time type: hour-minute-second-millisecond | 47 // * Time type: hour-minute-second-millisecond |
47 // * DateTime or DateTimeLocal type: year-month-day hour-minute-second-milliseco
nd | 48 // * DateTime or DateTimeLocal type: |
| 49 // year-month-day hour-minute-second-millisecond |
48 class PLATFORM_EXPORT DateComponents { | 50 class PLATFORM_EXPORT DateComponents { |
49 DISALLOW_NEW(); | 51 DISALLOW_NEW(); |
50 | 52 |
51 public: | 53 public: |
52 DateComponents() | 54 DateComponents() |
53 : m_millisecond(0), | 55 : m_millisecond(0), |
54 m_second(0), | 56 m_second(0), |
55 m_minute(0), | 57 m_minute(0), |
56 m_hour(0), | 58 m_hour(0), |
57 m_monthDay(0), | 59 m_monthDay(0), |
(...skipping 17 matching lines...) Expand all Loading... |
75 int minute() const { return m_minute; } | 77 int minute() const { return m_minute; } |
76 int hour() const { return m_hour; } | 78 int hour() const { return m_hour; } |
77 int monthDay() const { return m_monthDay; } | 79 int monthDay() const { return m_monthDay; } |
78 int weekDay() const; | 80 int weekDay() const; |
79 int month() const { return m_month; } | 81 int month() const { return m_month; } |
80 int fullYear() const { return m_year; } | 82 int fullYear() const { return m_year; } |
81 int week() const { return m_week; } | 83 int week() const { return m_week; } |
82 Type getType() const { return m_type; } | 84 Type getType() const { return m_type; } |
83 | 85 |
84 enum SecondFormat { | 86 enum SecondFormat { |
85 None, // Suppress the second part and the millisecond part if they are 0. | 87 None, // Suppress the second part and the millisecond part if they are 0. |
86 Second, // Always show the second part, and suppress the millisecond part i
f it is 0. | 88 Second, // Always show the second part, and suppress the millisecond part |
| 89 // if it is 0. |
87 Millisecond // Always show the second part and the millisecond part. | 90 Millisecond // Always show the second part and the millisecond part. |
88 }; | 91 }; |
89 | 92 |
90 // Returns an ISO 8601 representation for this instance. | 93 // Returns an ISO 8601 representation for this instance. |
91 // The format argument is valid for DateTime, DateTimeLocal, and Time types. | 94 // The format argument is valid for DateTime, DateTimeLocal, and Time types. |
92 String toString(SecondFormat format = None) const; | 95 String toString(SecondFormat format = None) const; |
93 | 96 |
94 // parse*() and setMillisecondsSince*() functions are initializers for an | 97 // parse*() and setMillisecondsSince*() functions are initializers for an |
95 // DateComponents instance. If these functions return false, the instance | 98 // DateComponents instance. If these functions return false, the instance |
96 // might be invalid. | 99 // might be invalid. |
(...skipping 19 matching lines...) Expand all Loading... |
116 bool parseDateTimeLocal(const String&, unsigned start, unsigned& end); | 119 bool parseDateTimeLocal(const String&, unsigned start, unsigned& end); |
117 | 120 |
118 // The following setMillisecondsSinceEpochFor*() functions take | 121 // The following setMillisecondsSinceEpochFor*() functions take |
119 // the number of milliseconds since 1970-01-01 00:00:00.000 UTC as | 122 // the number of milliseconds since 1970-01-01 00:00:00.000 UTC as |
120 // the argument, and update all fields for the corresponding | 123 // the argument, and update all fields for the corresponding |
121 // DateComponents type. The functions return true if it succeeds, and | 124 // DateComponents type. The functions return true if it succeeds, and |
122 // false if they fail. | 125 // false if they fail. |
123 | 126 |
124 // For Date type. Updates m_year, m_month and m_monthDay. | 127 // For Date type. Updates m_year, m_month and m_monthDay. |
125 bool setMillisecondsSinceEpochForDate(double ms); | 128 bool setMillisecondsSinceEpochForDate(double ms); |
126 // For DateTime type. Updates m_year, m_month, m_monthDay, m_hour, m_minute, m
_second and m_millisecond. | 129 // For DateTime type. Updates m_year, m_month, m_monthDay, m_hour, m_minute, |
| 130 // m_second and m_millisecond. |
127 bool setMillisecondsSinceEpochForDateTime(double ms); | 131 bool setMillisecondsSinceEpochForDateTime(double ms); |
128 // For DateTimeLocal type. Updates m_year, m_month, m_monthDay, m_hour, m_minu
te, m_second and m_millisecond. | 132 // For DateTimeLocal type. Updates m_year, m_month, m_monthDay, m_hour, |
| 133 // m_minute, m_second and m_millisecond. |
129 bool setMillisecondsSinceEpochForDateTimeLocal(double ms); | 134 bool setMillisecondsSinceEpochForDateTimeLocal(double ms); |
130 // For Month type. Updates m_year and m_month. | 135 // For Month type. Updates m_year and m_month. |
131 bool setMillisecondsSinceEpochForMonth(double ms); | 136 bool setMillisecondsSinceEpochForMonth(double ms); |
132 // For Week type. Updates m_year and m_week. | 137 // For Week type. Updates m_year and m_week. |
133 bool setMillisecondsSinceEpochForWeek(double ms); | 138 bool setMillisecondsSinceEpochForWeek(double ms); |
134 | 139 |
135 // For Time type. Updates m_hour, m_minute, m_second and m_millisecond. | 140 // For Time type. Updates m_hour, m_minute, m_second and m_millisecond. |
136 bool setMillisecondsSinceMidnight(double ms); | 141 bool setMillisecondsSinceMidnight(double ms); |
137 | 142 |
138 // Another initializer for Month type. Updates m_year and m_month. | 143 // Another initializer for Month type. Updates m_year and m_month. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 int m_month; // 0:January - 11:December | 229 int m_month; // 0:January - 11:December |
225 int m_year; // 1582 - | 230 int m_year; // 1582 - |
226 int m_week; // 1 - 53 | 231 int m_week; // 1 - 53 |
227 | 232 |
228 Type m_type; | 233 Type m_type; |
229 }; | 234 }; |
230 | 235 |
231 } // namespace blink | 236 } // namespace blink |
232 | 237 |
233 #endif // DateComponents_h | 238 #endif // DateComponents_h |
OLD | NEW |