Datetime problem

Report a typo

You take notes (maybe keep a diary?) and save them to a file. The notes can contain the date in the format dd/mm/yyyy (two or four digits by unit), or the time in the format hh:mm (two digits by unit), or both of them.

You get a line from the notes file and need to know if it has an indication of date or time. If the line contains a date, you need to print the message: "date", if it has the time, print out the message: "time". If the line contains both, print the message: "datetime". In other cases, print "none".

Sample Input 1:

10/04/1995 Mary birthdate

Sample Output 1:

date
Write a program in Go
package main

import (
"bufio"
"fmt"
"os"
"regexp"
)

func main() {
// DO NOT modify the code block below:
scanner := bufio.NewScanner(os.Stdin)
scanner.Scan()
note := scanner.Text()

// Create the 'date' and 'time' regexp templates below:
reDate := regexp.MustCompile(`..\/..\/....`) // date template
reTime := regexp.?(?) // time template

onDate := reDate.MatchString(note)
onTime := ?.MatchString(?)

switch {
case onDate && onTime:
fmt.Println("datetime")
case onDate:
fmt.Println("?")
case onTime:
fmt.Println("time")
default:
fmt.Println("?")
}
}
___

Create a free account to access the full topic