Giter Club home page Giter Club logo

Comments (2)

KaiserMarvin avatar KaiserMarvin commented on July 30, 2024 1

@ivoloshin thank you for the quick answer. For me, I actually solved it simply by running the job daily as from you suggested and using the already mentioned Cronos library (https://github.com/HangfireIO/Cronos) in the When function. For the future, however, it would of course be nice if Coravel itselfs supports the full cron expression scope natively.

from coravel.

ivoloshin avatar ivoloshin commented on July 30, 2024

You can probably do something like below. I assume it'll check daily at 6PM, and then run the predicate to check if it should run on that day.


scheduler.Schedule<MyJob>()
  .DailyAtHour(18)
  .When(IsLastWorkingDayOfMonth);

//compliments of ChatGPT with some mods
public async Task<bool> IsLastWorkingDayOfMonth()
{
	Func<DateTime, DateTime> GetLastWorkingDayOfMonth = date =>
	{
		DateTime lastDayOfMonth = new DateTime(date.Year, date.Month, DateTime.DaysInMonth(date.Year, date.Month));

		// Check if the last day of the month falls on a weekend
		if (lastDayOfMonth.DayOfWeek == DayOfWeek.Saturday)
		{
			return lastDayOfMonth.AddDays(-1); // If it's Saturday, return the previous Friday
		}
		else if (lastDayOfMonth.DayOfWeek == DayOfWeek.Sunday)
		{
			return lastDayOfMonth.AddDays(-2); // If it's Sunday, return the previous Friday
		}
		else
		{
			return lastDayOfMonth; // If it's a weekday, return the last day of the month
		}
	};

	DateTime today = DateTime.Today;
	DateTime lastWorkingDay = GetLastWorkingDayOfMonth(today);
	
	return lastWorkingDay == today;
}

from coravel.

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.