Skip to content

Allowing DateFormat in the parser #84

Answered by venkatd
venkatd asked this question in Q&A
Discussion options

You must be logged in to vote

Great! Will do. If I see any possibilities for improving the types will submit some issues and attempt a PR.

Here is what I have so far, maybe as reference to others looking into this library. I'm passing in a DateFormat class here so I can lean on the intl library to get things like month names, days of week, etc.

import 'package:intl/intl.dart';
import 'package:meta/meta.dart';
import 'package:petitparser/petitparser.dart';
import 'util.dart';

Parser<DateTime> dateTimeFromFormat(DateFormat format) {
  final num4Digits = digit().repeat(4).flatten().map(int.parse);

  final yyyy = string('yyyy').map((token) => num4Digits.map(_year));
  final y = string('y').map((_) => num4Digits.map(_yea…

Replies: 5 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by renggli
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #84 on December 08, 2020 19:52.