From 4022ae0c28262d615ec13bce2c682fbffe8a961b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A5=D0=BB=D1=8B=D1=81=D1=82=D0=BE=D0=B2=20=D0=9E=D0=BB?= =?UTF-8?q?=D0=B5=D0=B3=2008174=20RU?= Date: Wed, 21 Oct 2020 17:51:09 +0300 Subject: [PATCH] language code in DateFormat --- lib/date_time_picker.dart | 47 ++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/lib/date_time_picker.dart b/lib/date_time_picker.dart index b3dff66..60686ea 100644 --- a/lib/date_time_picker.dart +++ b/lib/date_time_picker.dart @@ -540,17 +540,16 @@ class _DateTimePickerState extends FormFieldState { } String lsValue = _effectiveController.text.trim(); - + String languageCode = widget.locale.languageCode; if (lsValue != null && lsValue != '' && lsValue != 'null') { if (widget.type != DateTimePickerType.time) { _dDate = DateTime.tryParse(lsValue); _tTime = TimeOfDay.fromDateTime(_dDate); - - _sDate = DateFormat('yyyy-MM-dd').format(_dDate); - _sTime = DateFormat('HH:mm').format(_dDate); + _sDate = DateFormat('yyyy-MM-dd', languageCode).format(_dDate); + _sTime = DateFormat('HH:mm', languageCode).format(_dDate); if (!widget.use24HourFormat) { - _sTime = DateFormat('hh:mm a').format(_dDate); + _sTime = DateFormat('hh:mm a', languageCode).format(_dDate); } _timeLabelController.text = _sTime; @@ -558,7 +557,7 @@ class _DateTimePickerState extends FormFieldState { if (widget.dateMask != null && widget.dateMask != '') { _dateLabelController.text = - DateFormat(widget.dateMask).format(_dDate); + DateFormat(widget.dateMask, languageCode).format(_dDate); } else { String lsMask = 'MMM d, yyyy'; @@ -570,7 +569,8 @@ class _DateTimePickerState extends FormFieldState { } } - _dateLabelController.text = DateFormat(lsMask).format(_dDate); + _dateLabelController.text = + DateFormat(lsMask, languageCode).format(_dDate); } } else { List llTime = lsValue.split(':'); @@ -591,6 +591,7 @@ class _DateTimePickerState extends FormFieldState { void didUpdateWidget(DateTimePicker oldWidget) { super.didUpdateWidget(oldWidget); + String languageCode = widget.locale.languageCode; if (widget.controller != oldWidget.controller) { oldWidget.controller?.removeListener(_handleControllerChanged); widget.controller?.addListener(_handleControllerChanged); @@ -619,14 +620,14 @@ class _DateTimePickerState extends FormFieldState { _dDate = DateTime.tryParse(lsValue); if (_dDate != null) { - _sDate = DateFormat('yyyy-MM-dd').format(_dDate); + _sDate = DateFormat('yyyy-MM-dd', languageCode).format(_dDate); if (lsOldTime != '') { _tTime = TimeOfDay.fromDateTime(_dDate); - _sTime = DateFormat('HH:mm').format(_dDate); + _sTime = DateFormat('HH:mm', languageCode).format(_dDate); if (!widget.use24HourFormat) { - _sTime = DateFormat('hh:mm a').format(_dDate); + _sTime = DateFormat('hh:mm a', languageCode).format(_dDate); } } } @@ -637,7 +638,7 @@ class _DateTimePickerState extends FormFieldState { if (_dDate != null) { if (widget.dateMask != null && widget.dateMask != '') { _dateLabelController.text = - DateFormat(widget.dateMask).format(_dDate); + DateFormat(widget.dateMask, languageCode).format(_dDate); } else { String lsMask = 'MMM d, yyyy'; @@ -649,7 +650,8 @@ class _DateTimePickerState extends FormFieldState { } } - _dateLabelController.text = DateFormat(lsMask).format(_dDate); + _dateLabelController.text = + DateFormat(lsMask, languageCode).format(_dDate); } } } else { @@ -715,19 +717,20 @@ class _DateTimePickerState extends FormFieldState { routeSettings: widget.routeSettings, ); + String languageCode = widget.locale.languageCode; if (ldDatePicked != null) { - _sDate = DateFormat('yyyy-MM-dd').format(ldDatePicked); + _sDate = DateFormat('yyyy-MM-dd', languageCode).format(ldDatePicked); _dDate = ldDatePicked; String lsOldValue = _sValue; _sValue = _sDate; String lsFormatedDate; if (widget.dateMask != null && widget.dateMask != '') { - lsFormatedDate = - DateFormat(widget.dateMask).format(DateTime.tryParse(_sDate)); + lsFormatedDate = DateFormat(widget.dateMask, languageCode) + .format(DateTime.tryParse(_sDate)); } else { - lsFormatedDate = - DateFormat('MMM dd, yyyy').format(DateTime.tryParse(_sDate)); + lsFormatedDate = DateFormat('MMM dd, yyyy', languageCode) + .format(DateTime.tryParse(_sDate)); } if (widget.type == DateTimePickerType.dateTimeSeparate && _sTime != '') { @@ -815,8 +818,9 @@ class _DateTimePickerState extends FormFieldState { routeSettings: widget.routeSettings, ); + String languageCode = widget.locale.languageCode; if (ldDatePicked != null) { - _sDate = DateFormat('yyyy-MM-dd').format(ldDatePicked); + _sDate = DateFormat('yyyy-MM-dd', languageCode).format(ldDatePicked); _dDate = ldDatePicked; TimeOfDay ltTimePicked = await showTimePicker( @@ -867,11 +871,12 @@ class _DateTimePickerState extends FormFieldState { _sValue = _sValue.trim(); if (widget.dateMask != null && widget.dateMask != '') { - lsFormatedDate = - DateFormat(widget.dateMask).format(DateTime.tryParse(_sValue)); + lsFormatedDate = DateFormat(widget.dateMask, languageCode) + .format(DateTime.tryParse(_sValue)); } else { String lsMask = _sTime != '' ? 'MMM dd, yyyy - HH:mm' : 'MMM dd, yyyy'; - lsFormatedDate = DateFormat(lsMask).format(DateTime.tryParse(_sValue)); + lsFormatedDate = + DateFormat(lsMask, languageCode).format(DateTime.tryParse(_sValue)); } _dateLabelController.text = lsFormatedDate;