Coder Social home page Coder Social logo

Date parser about show HOT 10 CLOSED

hello-rust avatar hello-rust commented on May 22, 2024
Date parser

from show.

Comments (10)

k0pernicus avatar k0pernicus commented on May 22, 2024 1

Hello :)

My solution is available here - it's really not perfect...

I can't wait to see your new video on the subject ;)

from show.

belfz avatar belfz commented on May 22, 2024 1

Hi @mre ! Thanks for this awesome challenge.

Here's my solution.

It uses std::str::FromStr trait and the ? (question mark) operator extensively (each parsing step returns a Result). It also checks whether a given day is valid in a given month (eg. 31 of April is considered invalid, because April has 30 days), although it's very forgiving when it comes to the special case of February (max. 29 is always allowed).

from show.

belfz avatar belfz commented on May 22, 2024 1

I updated my code - added leap year validation in case of February 29th 😉 .

from show.

LivingInSyn avatar LivingInSyn commented on May 22, 2024 1

Here's my submission, I used it as an excuse to learn a bit about nom. The tests aren't the BEST organized, but the majority are there:

https://gist.github.com/LivingInSyn/4a0b88a3cce0c58e9331f937aa520ab9

from show.

mre avatar mre commented on May 22, 2024 1







Whelp, something like this could work, yeah.

let day: u32 = parts[0].rmatches(char::is_numeric).nth(0)?.parse()?;

Here's the code with some error handling:
https://play.rust-lang.org/?gist=487104fd94fedde58d75ba0f480e4d49&version=nightly&mode=debug

Whether you prefer that over the given solution is a matter personal taste I guess. 😉

from show.

mre avatar mre commented on May 22, 2024

Thanks for that @k0pernicus 😃

from show.

mre avatar mre commented on May 22, 2024

Thanks you two! ❤️

from show.

SFrav avatar SFrav commented on May 22, 2024

Hey, instead of listing all options, can we do something like this:
let day: u32 = parts[0].rmatches(char::is_numeric).collect()?;

If so, how would you add error handling?

I’m liking the episodes by the way. Keep up the good work!

from show.

mre avatar mre commented on May 22, 2024

Thanks for all the contribution. Show notes are here: https://github.com/hello-rust/show/tree/master/episode/7.
I really appreciate it and it makes the show better.
I might ask you to do more of that in the future and contribute to a future episode.
Might be more code samples, might be reviewing my code, might be an interview - who knows.
But I hope we can keep this going as I love to learn from your code and your feedback! ❤️

from show.

LivingInSyn avatar LivingInSyn commented on May 22, 2024

I'd be more than happy to help further, the 'assignment' was fun and an excuse to learn something new :)

from show.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.