Skip to content

Commit efbac6c

Browse files
committed
chore: check time format & add time format test
1 parent 76079d8 commit efbac6c

File tree

8 files changed

+199
-72
lines changed

8 files changed

+199
-72
lines changed

frontend/app_flowy/lib/workspace/application/grid/cell/date_cal_bloc.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'dart:async';
99
import 'cell_service/cell_service.dart';
1010
import 'package:dartz/dartz.dart';
1111
import 'package:protobuf/protobuf.dart';
12-
import 'package:fixnum/fixnum.dart' as $fixnum;
12+
// import 'package:fixnum/fixnum.dart' as $fixnum;
1313
part 'date_cal_bloc.freezed.dart';
1414

1515
class DateCalBloc extends Bloc<DateCalEvent, DateCalState> {
@@ -163,9 +163,10 @@ class DateCalState with _$DateCalState {
163163
Option<DateCellPersistenceData> dateData = none();
164164
final time = cellData?.time ?? "";
165165
if (cellData != null) {
166-
final timestamp = $fixnum.Int64.parseInt(cellData.date).toInt();
167-
final selectedDay = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000);
168-
dateData = Some(DateCellPersistenceData(date: selectedDay));
166+
// final timestamp = $fixnum.Int64.parseInt(cellData.timestamp).toInt();
167+
final timestamp = cellData.timestamp * 1000;
168+
final selectedDay = DateTime.fromMillisecondsSinceEpoch(timestamp.toInt());
169+
dateData = Some(DateCellPersistenceData(date: selectedDay, time: time));
169170
}
170171

171172
return DateCalState(

frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/date_cell/calendar.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class _CellCalendarWidget extends StatelessWidget {
127127
if (state.dateTypeOption.includeTime) {
128128
children.addAll([
129129
_TimeTextField(
130-
time: "",
130+
text: state.time,
131131
errorText: state.inputTimeError.fold(() => "", (error) => error.toString()),
132132
onEditingComplete: (text) {
133133
context.read<DateCalBloc>().add(DateCalEvent.setTime(text));
@@ -247,11 +247,11 @@ class _IncludeTimeButton extends StatelessWidget {
247247

248248
class _TimeTextField extends StatefulWidget {
249249
final String errorText;
250-
final String time;
250+
final String text;
251251
final void Function(String) onEditingComplete;
252252
const _TimeTextField({
253253
Key? key,
254-
required this.time,
254+
required this.text,
255255
required this.errorText,
256256
required this.onEditingComplete,
257257
}) : super(key: key);
@@ -267,7 +267,7 @@ class _TimeTextFieldState extends State<_TimeTextField> {
267267
@override
268268
void initState() {
269269
_focusNode = FocusNode();
270-
_controller = TextEditingController(text: widget.time);
270+
_controller = TextEditingController(text: widget.text);
271271
_focusNode.addListener(() {
272272
if (mounted) {
273273
widget.onEditingComplete(_controller.text);

frontend/app_flowy/packages/flowy_infra_ui/lib/widget/rounded_input_field.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ class _RoundedInputFieldState extends State<RoundedInputField> {
6060
@override
6161
void initState() {
6262
obscuteText = widget.obscureText;
63+
if (widget.controller != null) {
64+
inputText = widget.controller!.text;
65+
} else {
66+
inputText = widget.initialValue ?? "";
67+
}
68+
6369
super.initState();
6470
}
6571

frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-grid/date_type_option.pb.dart

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-grid/date_type_option.pbjson.dart

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/rust-lib/flowy-grid/src/protobuf/model/date_type_option.rs

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ pub struct DateCellData {
242242
// message fields
243243
pub date: ::std::string::String,
244244
pub time: ::std::string::String,
245+
pub timestamp: i64,
245246
// special fields
246247
pub unknown_fields: ::protobuf::UnknownFields,
247248
pub cached_size: ::protobuf::CachedSize,
@@ -309,6 +310,21 @@ impl DateCellData {
309310
pub fn take_time(&mut self) -> ::std::string::String {
310311
::std::mem::replace(&mut self.time, ::std::string::String::new())
311312
}
313+
314+
// int64 timestamp = 3;
315+
316+
317+
pub fn get_timestamp(&self) -> i64 {
318+
self.timestamp
319+
}
320+
pub fn clear_timestamp(&mut self) {
321+
self.timestamp = 0;
322+
}
323+
324+
// Param is passed by value, moved
325+
pub fn set_timestamp(&mut self, v: i64) {
326+
self.timestamp = v;
327+
}
312328
}
313329

314330
impl ::protobuf::Message for DateCellData {
@@ -326,6 +342,13 @@ impl ::protobuf::Message for DateCellData {
326342
2 => {
327343
::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.time)?;
328344
},
345+
3 => {
346+
if wire_type != ::protobuf::wire_format::WireTypeVarint {
347+
return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type));
348+
}
349+
let tmp = is.read_int64()?;
350+
self.timestamp = tmp;
351+
},
329352
_ => {
330353
::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?;
331354
},
@@ -344,6 +367,9 @@ impl ::protobuf::Message for DateCellData {
344367
if !self.time.is_empty() {
345368
my_size += ::protobuf::rt::string_size(2, &self.time);
346369
}
370+
if self.timestamp != 0 {
371+
my_size += ::protobuf::rt::value_size(3, self.timestamp, ::protobuf::wire_format::WireTypeVarint);
372+
}
347373
my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields());
348374
self.cached_size.set(my_size);
349375
my_size
@@ -356,6 +382,9 @@ impl ::protobuf::Message for DateCellData {
356382
if !self.time.is_empty() {
357383
os.write_string(2, &self.time)?;
358384
}
385+
if self.timestamp != 0 {
386+
os.write_int64(3, self.timestamp)?;
387+
}
359388
os.write_unknown_fields(self.get_unknown_fields())?;
360389
::std::result::Result::Ok(())
361390
}
@@ -404,6 +433,11 @@ impl ::protobuf::Message for DateCellData {
404433
|m: &DateCellData| { &m.time },
405434
|m: &mut DateCellData| { &mut m.time },
406435
));
436+
fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeInt64>(
437+
"timestamp",
438+
|m: &DateCellData| { &m.timestamp },
439+
|m: &mut DateCellData| { &mut m.timestamp },
440+
));
407441
::protobuf::reflect::MessageDescriptor::new_pb_name::<DateCellData>(
408442
"DateCellData",
409443
fields,
@@ -422,6 +456,7 @@ impl ::protobuf::Clear for DateCellData {
422456
fn clear(&mut self) {
423457
self.date.clear();
424458
self.time.clear();
459+
self.timestamp = 0;
425460
self.unknown_fields.clear();
426461
}
427462
}
@@ -886,15 +921,16 @@ static file_descriptor_proto_data: &'static [u8] = b"\
886921
ateTypeOption\x12,\n\x0bdate_format\x18\x01\x20\x01(\x0e2\x0b.DateFormat\
887922
R\ndateFormat\x12,\n\x0btime_format\x18\x02\x20\x01(\x0e2\x0b.TimeFormat\
888923
R\ntimeFormat\x12!\n\x0cinclude_time\x18\x03\x20\x01(\x08R\x0bincludeTim\
889-
e\"6\n\x0cDateCellData\x12\x12\n\x04date\x18\x01\x20\x01(\tR\x04date\x12\
890-
\x12\n\x04time\x18\x02\x20\x01(\tR\x04time\"\xa1\x01\n\x14DateChangesetP\
891-
ayload\x12?\n\x0fcell_identifier\x18\x01\x20\x01(\x0b2\x16.CellIdentifie\
892-
rPayloadR\x0ecellIdentifier\x12\x14\n\x04date\x18\x02\x20\x01(\tH\0R\x04\
893-
date\x12\x14\n\x04time\x18\x03\x20\x01(\tH\x01R\x04timeB\r\n\x0bone_of_d\
894-
ateB\r\n\x0bone_of_time*6\n\nDateFormat\x12\t\n\x05Local\x10\0\x12\x06\n\
895-
\x02US\x10\x01\x12\x07\n\x03ISO\x10\x02\x12\x0c\n\x08Friendly\x10\x03*0\
896-
\n\nTimeFormat\x12\x0e\n\nTwelveHour\x10\0\x12\x12\n\x0eTwentyFourHour\
897-
\x10\x01b\x06proto3\
924+
e\"T\n\x0cDateCellData\x12\x12\n\x04date\x18\x01\x20\x01(\tR\x04date\x12\
925+
\x12\n\x04time\x18\x02\x20\x01(\tR\x04time\x12\x1c\n\ttimestamp\x18\x03\
926+
\x20\x01(\x03R\ttimestamp\"\xa1\x01\n\x14DateChangesetPayload\x12?\n\x0f\
927+
cell_identifier\x18\x01\x20\x01(\x0b2\x16.CellIdentifierPayloadR\x0ecell\
928+
Identifier\x12\x14\n\x04date\x18\x02\x20\x01(\tH\0R\x04date\x12\x14\n\
929+
\x04time\x18\x03\x20\x01(\tH\x01R\x04timeB\r\n\x0bone_of_dateB\r\n\x0bon\
930+
e_of_time*6\n\nDateFormat\x12\t\n\x05Local\x10\0\x12\x06\n\x02US\x10\x01\
931+
\x12\x07\n\x03ISO\x10\x02\x12\x0c\n\x08Friendly\x10\x03*0\n\nTimeFormat\
932+
\x12\x0e\n\nTwelveHour\x10\0\x12\x12\n\x0eTwentyFourHour\x10\x01b\x06pro\
933+
to3\
898934
";
899935

900936
static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT;

frontend/rust-lib/flowy-grid/src/protobuf/proto/date_type_option.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ message DateTypeOption {
99
message DateCellData {
1010
string date = 1;
1111
string time = 2;
12+
int64 timestamp = 3;
1213
}
1314
message DateChangesetPayload {
1415
CellIdentifierPayload cell_identifier = 1;

0 commit comments

Comments
 (0)