Professional Services Automation Apex API Developer Reference

pse.CalendarUtil

global with sharing class CalendarUtil

Utilities relating to days and dates.

Enums

DayOfWeek

Value Description
SUNDAY Sunday
MONDAY Monday
TUESDAY Tuesday
WEDNESDAY Wednesday
THURSDAY Thursday
FRIDAY Friday
SATURDAY Saturday

Methods

getDayOfWeek

global static pse.CalendarUtil.DayOfWeek getDayOfWeek(Date dt)

Returns the day of the week for the provided Date.

Input Parameters

Name Type Description
dt Date Input date

getStartOfWeek

global static Date getStartOfWeek(Date refDate, pse.CalendarUtil.DayOfWeek weekStartDay)

Find the start date of the week containing the requested date. The weekStartDay (e.g. Monday) determines which day is considered to be the start of a week.

Input Parameters

Name Type Description
refDate Date Input date.
weekStartDay pse.CalendarUtil.DayOfWeek Week start day for this calculation.

Sample Code

//Note: This sample code is for demonstration purposes only. It is not intended for
//use in a production environment, is not guaranteed against defects or errors, and
//is in no way optimized or streamlined.

System.debug(
    pse.CalendarUtil.getStartOfWeek(
        Date.newInstance(2022, 5, 27),
        pse.CalendarUtil.DayOfWeek.MONDAY
    )
);
//2022-05-23

System.debug(
    pse.CalendarUtil.getStartOfWeek(
        Date.newInstance(2022, 5, 29),
        pse.CalendarUtil.DayOfWeek.SUNDAY
    )
);
//2022-05-29
© Copyright 2009–2024 Certinia Inc. All rights reserved. Various trademarks held by their respective owners.