Locale DateTime for tr_TR is not working?

3,959 views
Skip to first unread message

Niyazi Toros

unread,
Apr 25, 2018, 8:18:49 AM4/25/18
to Flutter Dev
Hi,

The tr_TR locale DateTime now() is not working. The en_US is working.

Below there is a working code sample and none working code sample and
the flutter error text.

I am using macOS High Sierra and my locale already set to Turkey.
I am from Nicosia North Cyprus (Turkish Part). 

Any help please?


 

Working Code:
//-------------------------------------------------------------------------------------------------------
import 'package:intl/intl.dart';
pubspec.yaml also has intl: ^0.15.6

var format = new DateFormat.yMMMd("en_US").add_jm();
var date = format.format(DateTime.now());
print(date);


Faild Code:
//-------------------------------------------------------------------------------------------------------
import 'package:intl/intl.dart';
pubspec.yaml also has intl: ^0.15.6

var format = new DateFormat.yMMMd("tr_TR").add_jm();
var date = format.format(DateTime.now());
print(date);


/*

Launching lib/main.dart on Android SDK built for x86 in debug mode...
Initializing gradle...
Resolving dependencies...
Running 'gradlew assembleDebug'...
Built build/app/outputs/apk/debug/app-debug.apk (30.9MB).
Installing build/app/outputs/apk/app.apk...
I/FlutterActivityDelegate(22980): onResume setting current activity to this
E/flutter (22980): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter (22980): LocaleDataException: Locale data has not been initialized, call initializeDateFormatting(<locale>).
E/flutter (22980): #0      UninitializedLocaleData._throwException (package:intl/src/intl_helpers.dart:71:5)
E/flutter (22980): #1      UninitializedLocaleData.containsKey (package:intl/src/intl_helpers.dart:68:61)
E/flutter (22980): #2      DateFormat.localeExists (file:///Users/niyazitoros/.pub-cache/hosted/pub.dartlang.org/intl-0.15.6/lib/src/intl/date_format.dart:753:28)
E/flutter (22980): #3      Intl.verifiedLocale (package:intl/intl.dart:222:21)
E/flutter (22980): #4      new DateFormat (file:///Users/niyazitoros/.pub-cache/hosted/pub.dartlang.org/intl-0.15.6/lib/src/intl/date_format.dart:246:20)
E/flutter (22980): #5      new DateFormat.yMMMd (file:///Users/niyazitoros/.pub-cache/hosted/pub.dartlang.org/intl-0.15.6/lib/src/intl/date_format.dart)
E/flutter (22980): #6      main (file:///Users/niyazitoros/IdeaProjects/quakescyprus/lib/main.dart:36:19)
E/flutter (22980): <asynchronous suspension>
E/flutter (22980): #7      _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:279:19)
E/flutter (22980): #8      _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)
Syncing files to device Android SDK built for x86...
Error -32601 received from application: Method not found
Error -32601 received from application: Method not found
Error -32601 received from application: Method not found
Error -32601 received from application: Method not found

*/

Ralph Bergmann

unread,
Apr 25, 2018, 8:22:14 AM4/25/18
to flutt...@googlegroups.com
I didn't test it, but I guess this is the crucial line from your stack
trace:

E/flutter (22980): LocaleDataException: Locale data has not been
initialized, call initializeDateFormatting(<locale>).


Ralph


Am 25.04.18 um 14:18 schrieb Niyazi Toros:
> *Hi,*
>
> The *tr_TR* locale DateTime now() is not working. The *en_US* is working.
>
> Below there is a working code sample and none working code sample and
> the flutter error text.
>
> I am using macOS High Sierra and my locale already set to Turkey.
> I am from Nicosia North Cyprus (Turkish Part). 
>
> Any help please?
>
>
>  
>
> *Working Code:*
> *//-------------------------------------------------------------------------------------------------------*
>
> import 'package:intl/intl.dart';
>
> *pubspec.yaml also has *intl: ^0.15.6
>
>
> var format = new DateFormat.yMMMd("en_US").add_jm();
> var date = format.format(DateTime.now());
> print(date);
>
>
>
> *Faild Code:*
> *//-------------------------------------------------------------------------------------------------------*
>
> import 'package:intl/intl.dart';
>
> *pubspec.yaml also has *intl: ^0.15.6
> --
> You received this message because you are subscribed to the Google
> Groups "Flutter Dev" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to flutter-dev...@googlegroups.com
> <mailto:flutter-dev...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.


--

Ralph Bergmann


www http://www.dasralph.de | http://www.the4thFloor.eu
mail ra...@dasralph.de
skype dasralph

facebook https://www.facebook.com/dasralph
google+ https://plus.google.com/+RalphBergmann
xing https://www.xing.com/profile/Ralph_Bergmann3
linkedin https://www.linkedin.com/in/ralphbergmann
github https://github.com/the4thfloor


pgp key id 0x421F9B78
pgp fingerprint CEE3 7AE9 07BE 98DF CD5A E69C F131 4A8E 421F 9B78

signature.asc

Niyazi Toros

unread,
Apr 25, 2018, 8:41:16 AM4/25/18
to Flutter Dev
@Ralph

thank you for quick response. But I dont know where to get info for "call initializeDateFormatting(<locale>). ".
below code: 

And I get currley red underline under initializeDateFormatting. Any help please.

void setupLanguage(){
 
var trDatesFuture = initializeDateFormatting('tr', null);
 
Future
     
.wait([
    trDatesFuture
,
 
]);
}




25 Nisan 2018 Çarşamba 15:18:49 UTC+3 tarihinde Niyazi Toros yazdı:

Ralph Bergmann

unread,
Apr 25, 2018, 8:55:28 AM4/25/18
to flutt...@googlegroups.com
this:

import 'dart:async';

import 'package:intl/date_symbol_data_local.dart' as intl_local_date_data;
import 'package:intl/intl.dart';

Future<Null> main() async {
await intl_local_date_data.initializeDateFormatting();
var format = new DateFormat.yMMMd("tr_TR").add_jm();
var date = format.format(new DateTime.now());
print(date);
}

prints this:

25 Nis 2018 14:54



Ralph


Am 25.04.18 um 14:41 schrieb Niyazi Toros:
> @Ralph
>
> thank you for quick response. But I dont know where to get info for
> "call initializeDateFormatting(<locale>). ".
> I found this link
> "https://stackoverflow.com/questions/36174033/intl-package-and-date-formatting-strange-behaviour"
> and try to implement
> below code: 
>
> And I get currley red underline under initializeDateFormatting. Any help
> please.
> *
> *
> voidsetupLanguage(){
>   vartrDatesFuture =initializeDateFormatting('tr',null);
>   Future
>       .wait([
>     trDatesFuture,
>   ]);
> }
> */
> /*
signature.asc

Niyazi Toros

unread,
Apr 25, 2018, 9:27:05 AM4/25/18
to Flutter Dev
Hi @Ralph,

I try to implement your answer and I couldn't print the date.
Below code is part of the my app. Any help please?


import 'package:flutter/material.dart';


// FOR JSON

import 'dart:async';

import 'dart:convert';

import 'package:http/http.dart' as http;


// For DATE & LOCALE

import 'package:intl/intl.dart';

import 'package:intl/date_symbol_data_local.dart' as intl_local_date_data;



// Global Variable

var _mDate;


// Main Class

void main() async {


// GET DATE TIME NOW *********************************************************

_mDate = getLoacleAndDate;

print(_mDate);

// ***************************************************************************


   ….

   …

}



Future<String> getLoacleAndDate() async {

await intl_local_date_data.initializeDateFormatting();

var format = new DateFormat.yMMMd("tr_TR").add_jm();

var date = format.format(new DateTime.now());

var mxDate = date;

return mxDate;

debugPrint(mxDate);

print(mxDate);

}




Launching lib/main.dart on Android SDK built for x86 in debug mode...

Initializing gradle...

Resolving dependencies...

Running 'gradlew assembleDebug'...

Built build/app/outputs/apk/debug/app-debug.apk (31.0MB).

Installing build/app/outputs/apk/app.apk...

I/FlutterActivityDelegate(26301): onResume setting current activity to this

I/flutter (26301): Closure: () => Future<String> from Function 'getLoacleAndDate': static.

Syncing files to device Android SDK built for x86...

D/        (26301): HostConnection::get() New Host Connection established 0xa11a67c0, tid 26321

D/EGL_emulation(26301): eglMakeCurrent: 0xa245d580: ver 3 0 (tinfo 0x8f341db0)










25 Nisan 2018 Çarşamba 15:18:49 UTC+3 tarihinde Niyazi Toros yazdı:
Hi,

Ralph Bergmann

unread,
Apr 25, 2018, 9:36:35 AM4/25/18
to flutt...@googlegroups.com
Am 25.04.18 um 15:27 schrieb Niyazi Toros:
> Future<String> getLoacleAndDate() *async **{*
> ***await *intl_local_date_data.initializeDateFormatting()*;*
> ***var *format = *new *DateFormat.yMMMd("tr_TR").add_jm()*;*
> ***var *date = format.format(*new *DateTime.now())*;*
> ***var *mxDate = date*;*
> ***return *mxDate*;*
> **debugPrint(mxDate)*;*
> **print(mxDate)*;*
> *}*

What are you using for development? Please use an IDE for development,
e.g. Android Studio is for free and it will tell you what's going wrong.

As long as you wait for the download finishes: try to call print()
before you leave the method (1st call print(mxDate), 2nd call return mxDate)


Ralph

signature.asc

Niyazi Toros

unread,
Apr 25, 2018, 9:52:09 AM4/25/18
to Flutter Dev
Hi @Ralph

I am using IntelliJ 2018.1 on macOS high Sierra.
Print before return was my mistake. I corrected and but still didn't get any result.

In my app and the other Future json method is working. But the "Future<String> getLoacleAndDate() async" is not working.
Any help please?


//Working Future:
Future<Map> getQuakes() async {
String apiUrl = "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson";
http.Response response = await http.get(apiUrl);
return json.decode(response.body);
}


//None working Future:
Future<String> getLoacleAndDate() async {
await intl_local_date_data.initializeDateFormatting();
 var format = new DateFormat.yMMMd("tr_TR").add_jm();
 var date = format.format(new DateTime.now());
var mxDate = date;
 debugPrint(mxDate);
print(mxDate);
return mxDate;
}

Result:
--------------------
Launching lib/main.dart on Android SDK built for x86 in debug mode...
Initializing gradle...
Resolving dependencies...
Running 'gradlew assembleDebug'...
Built build/app/outputs/apk/debug/app-debug.apk (31.0MB).
Installing build/app/outputs/apk/app.apk...
I/FlutterActivityDelegate(28679): onResume setting current activity to this
I/flutter (28679): Closure: () => Future<String> from Function 'getLoacleAndDate': static.
Syncing files to device Android SDK built for x86...
Error -32601 received from application: Method not found
Error -32601 received from application: Method not found
Error -32601 received from application: Method not found
Error -32601 received from application: Method not found
I/flutter (28679): [{type: Feature, properties: {mag: 1.29, place: 18km SSW of Ocotillo Wells, CA, time: 1524664049370, updated: 1524664182413, tz: -480, url: https://earthquake.usgs.gov/earthquakes/eventpage/ci37923399, detail: https://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/ci37923399.geojson, felt: null, cdi: null, mmi: null, alert: null, status: automatic, tsunami: 0, sig: 26, net: ci, code: 37923399, ids: ,ci37923399,, sources: ,ci,, types: ,geoserve,nearby-cities,origin,phase-data,scitech-link,, nst: 35, dmin: 0.1568, rms: 0.25, gap: 98, magType: ml, type: earthquake, title: M 1.3 - 18km SSW of Ocotillo Wells, CA}, geometry: {type: Point, coordinates: [-116.2318344, 33.0079994, 6.32]}, id: ci37923399}, {type: Feature, properties: {mag: 1.7, place: 4km NNW of Pinnacles, CA, time: 1524663505780, updated: 1524664081824, tz: -480, url: https://earthquake.usgs.gov/earthquakes/eventpage/nc73005876, detail: https://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/nc73005876.geojson, felt: null, cdi: null, mmi: null, al
D/        (28679): HostConnection::get() New Host Connection established 0xa3e1a600, tid 28698
D/EGL_emulation(28679): eglMakeCurrent: 0xa3b08c40: ver 3 0 (tinfo 0xa3e032e0)






25 Nisan 2018 Çarşamba 15:18:49 UTC+3 tarihinde Niyazi Toros yazdı:
Hi,
Reply all
Reply to author
Forward
0 new messages