0

I have a repeating schedule in (dayOfWeek) (hour) (minutes) (seconds) That is passed in as a string. MONDAY-18-20-00 I would like to convert that as a CRON Expression and store it in the database. What would be the easiest way to do this ?

w2olves
  • 2,229
  • 10
  • 33
  • 60
  • you can use this and write extension method for make it easier https://stackoverflow.com/a/9398804/11104908 – Akbar Asghari Dec 06 '21 at 20:14
  • Probably best to store as `dayOfWeek tinyint` and `timeOfDay time` – Charlieface Dec 06 '21 at 20:19
  • You have 2 questions here, how create a Cron Expression, or how to use a database? Have you used Cron, do you know the basic structure? how far did you get? – TheGeneral Dec 06 '21 at 20:55
  • @TheGeneral I am asking a simple way to convert a (dayOfWeek) (hour) (minutes) (seconds) to a cron expression that I can save to database as a string. – w2olves Dec 06 '21 at 21:08
  • Let me know if the answer doesn't work, or I have misunderstood and ill delete it – TheGeneral Dec 06 '21 at 21:32

1 Answers1

0

If you are just needing to convert the current format into a cron format, then the following may work for you

var weirdInput = "MONDAY-18-20-00";

var split = weirdInput.Split("-");

var result = $"{split[3]} {split[2]} {split[1]} ? * {split[0][..3]}";

Output Cron

// At 18:20:00pm, on every Monday, every month
00 20 18 ? * MON
TheGeneral
  • 79,002
  • 9
  • 103
  • 141