本文整理汇总了C#中System.DateTime.StartOfWeek方法的典型用法代码示例。如果您正苦于以下问题:C# DateTime.StartOfWeek方法的具体用法?C# DateTime.StartOfWeek怎么用?C# DateTime.StartOfWeek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.DateTime
的用法示例。
在下文中一共展示了DateTime.StartOfWeek方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestStartOfWeek
public void TestStartOfWeek()
{
DateTime dt = new DateTime(2014, 3, 13);
Assert.AreEqual(new DateTime(2014, 3, 10), dt.StartOfWeek(DayOfWeek.Monday));
Assert.AreEqual(new DateTime(2014, 3, 9), dt.StartOfWeek(DayOfWeek.Sunday));
DateTime dt2 = new DateTime(2016, 5, 1);
Assert.AreEqual(new DateTime(2016, 4, 30), dt2.StartOfWeek(DayOfWeek.Saturday));
}
示例2: StartOfWeekWithCustomDayOfWeekShouldReturnExpectedResult
public void StartOfWeekWithCustomDayOfWeekShouldReturnExpectedResult()
{
var date = new DateTime( 2013, 3, 1 );
var expected = new DateTime( 2013, 2, 24 );
var actual = date.StartOfWeek( DayOfWeek.Sunday );
Assert.Equal( expected.Date, actual.Date );
expected = new DateTime( 2013, 2, 25 );
actual = date.StartOfWeek( DayOfWeek.Monday );
Assert.Equal( expected.Date, actual.Date );
}
示例3: StartOfWeekTestCase
public void StartOfWeekTestCase()
{
var dateTime = new DateTime( 2014, 3, 27 );
var expected = new DateTime( 2014, 3, 24 );
var actual = dateTime.StartOfWeek();
Assert.AreEqual( expected, actual );
expected = new DateTime( 2014, 3, 26 );
actual = dateTime.StartOfWeek( DayOfWeek.Wednesday );
Assert.AreEqual( expected, actual );
}
示例4: GroupNotes
public GroupNotes()
{
InitializeComponent();
admin = false;
String query = "select ClientNum, ClientName from ClientInfo where IntakeDate not like '0001-01-01%' and ExitDate like '0001-01-01%'";
clients = database.GetTable(query);
editingDay = DateTime.Now;
lastDayOfWeek = editingDay.Next(DayOfWeek.Sunday);
firstDayOfWeek = editingDay.StartOfWeek(DayOfWeek.Monday);
dayOfWeek = editingDay.DayOfWeek.ToString();
WeekOf_Label.Text = "Week of " + firstDayOfWeek.ToString("MM/dd") + " through " + lastDayOfWeek.ToString("MM/dd");
updateClientList();
clientList.SetSelected(0, true);
newPDFPath = "/clientfiles/groupnotes/" + loadClientID + "/"; // C:\\Users/Darryl/SparkleShare/WestSlopeSecure
newFile = newPDFPath + firstDayOfWeek.ToString("MM-dd-yyyy") + ".pdf";
templatePathFromOld = newPDFPath + firstDayOfWeek.ToString("MM-dd-yyyy") + "-old.pdf";
// Wipe out shit files.
if (Directory.Exists(newPDFPath))
{
foreach (var file in Directory.EnumerateFiles(newPDFPath, "*-old.pdf", SearchOption.TopDirectoryOnly))
File.Delete(file);
}
processPdfGen();
DaySelection.SelectedIndex = ((int)(editingDay.DayOfWeek) + 6) % 7;
}
示例5: checkForTimesheet
public void checkForTimesheet(string userName, DateTime tsDate)
{
Authentication auth = new Authentication();
if (auth.isUser(this) || Authentication.DEBUG_bypassAuth)
{
Timesheet resulttimesheet = new Timesheet();
DateTime startDay = tsDate.StartOfWeek(DayOfWeek.Sunday);
//Check if there is a timesheet for the week that corresponds to newhours.timestamp
var searchTs = from m in TimesheetDB.TimesheetList
where (m.worker.CompareTo(userName) == 0)
where m.periodStart <= tsDate
where m.periodEnd >= tsDate
select m;
foreach (var item in searchTs)
{
resulttimesheet = item;
}
//if there isn't a timesheet for the pay period, then create one
//If there is a timesheet for the current pay period, don't do anything
if (resulttimesheet.periodStart.CompareTo(startDay) != 0)
{
createTimesheet(userName, startDay);
return;
}
return;
}
else
{
return;
}
}
示例6: StartOfWeekShouldReturnExpectedResult
public void StartOfWeekShouldReturnExpectedResult()
{
var date = new DateTime( 2013, 3, 1 );
var expected = new DateTime( 2013, 2, 24 );
var actual = date.StartOfWeek();
Assert.Equal( expected.Date, actual.Date );
}
示例7: StartOfWeekTestCase2
public void StartOfWeekTestCase2()
{
var week = new DateTime( 2014, 09, 21 );
var expected = new DateTime( 2014, 09, 20 );
var actual = week.StartOfWeek( DayOfWeek.Saturday );
Assert.AreEqual( expected, actual );
}
示例8: StartOfWeek
public void StartOfWeek()
{
// Type
var @this = new DateTime(2014, 04, 16);
// Examples
DateTime value = @this.StartOfWeek(); // value = "2013/04/13 00:00:00:000";
// Unit Test
Assert.AreEqual(new DateTime(2014, 04, 13), value);
}
示例9: DateTimeHelper
public DateTimeHelper()
{
_now = DateTime.Now;
_todayStartDate = _now.Hour < 4
? new DateTime(_now.Year, _now.Month, _now.Day, 4, 0, 0).AddDays(-1)
: new DateTime(_now.Year, _now.Month, _now.Day, 4, 0, 0);
_todayEndDate = _todayStartDate.AddHours(24);
NextDay = _todayEndDate;
_weekStartDate = _now.StartOfWeek(DayOfWeek.Monday).AddHours(4);
_weekEndDate = _weekStartDate.AddDays(7);
NextWeek = _weekEndDate;
}
示例10: CreateTasksForWeek
public IEnumerable<Task> CreateTasksForWeek(DateTime week)
{
var tasks = new List<Task>();
DateTime weekStart = week.StartOfWeek(DayOfWeek.Monday);
for (var day = weekStart; (day - weekStart).Days < 7; day = day.AddDays(1))
{
if (IncludesDay(day)) tasks.Add(new Task {
ActivityId = Activity.ActivityId,
Activity = Activity,
Start = day,
Finished = false
});
}
return tasks;
}
示例11: GetMemberAttendanceObject
private MemberAttendanceForView GetMemberAttendanceObject(Attendance attendance, List<MemberAttendance> memberAttendances, DateTime weekRequested)
{
var mondayDate = weekRequested.StartOfWeek(DayOfWeek.Monday); // DateTime.Now.StartOfWeek(DayOfWeek.Monday);
return new MemberAttendanceForView
{
Attendance = attendance,
AttendanceId = attendance.AttendanceId,
MemberAttendances = memberAttendances,
Projects = _unitOfWork.ProjectRepository.Get().ToList(),
MondayDate = mondayDate.ToShortDateString(),
TuesdayDate = mondayDate.AddDays(1).ToShortDateString(),
WednesdayDate = mondayDate.AddDays(2).ToShortDateString(),
ThursdayDate = mondayDate.AddDays(3).ToShortDateString(),
FridayDate = mondayDate.AddDays(4).ToShortDateString(),
SaturdayDate = mondayDate.AddDays(5).ToShortDateString(),
SundayDate = mondayDate.AddDays(6).ToShortDateString()
};
}
示例12: GetLastStartWeek
private DateTime GetLastStartWeek(DateTime lastStart)
{
return lastStart.StartOfWeek(DayOfWeek.Monday).AddDays(7).Add(GetLeagueStartTimeSpan());
}
示例13: userManagement
//
/* Retrieves all the employee objects of employees that work for the specified departement
* within the Information Technology division (as per client request), then returns them
* as a list. If department is null, it displays all employees in the division
*/
public virtual ActionResult userManagement(DateTime refDate, string department = null)
{
Authentication auth = new Authentication();
if (auth.isManager(this) || Authentication.DEBUG_bypassAuth)
{
//if it's a redirect from submitRejectTimesheet()
if (TempData["emailSentFlag"] != null)
{
ViewBag.emailSentFlag = true;
ViewBag.messageRecipient = TempData["recipient"];
}
string division = getUserDivision();
IEnumerable<TARSUser> employees = getDivisionEmployeeObjList(division, department);
ViewBag.division = division;
ViewBag.departmentList = getDepartmentSelectList(division);
ViewBag.refDate = refDate;
ViewBag.refSunday = refDate.StartOfWeek(DayOfWeek.Sunday);
ViewBag.refPayPeriod = getPayPeriod(refDate);
return View(employees);
}
else
{
return View("error");
}
}
示例14: GivenADateTimeThenReturnThePreviousMondayDateTime
public void GivenADateTimeThenReturnThePreviousMondayDateTime(DateTime dateTime, DateTime answer)
{
var startOfWeek = dateTime.StartOfWeek();
Assert.AreEqual(startOfWeek, answer);
}
示例15: getPayPeriod
//
//Returns the pay period for the reference date as a string
public virtual string getPayPeriod(DateTime refDate)
{
DateTime startDay = refDate.StartOfWeek(DayOfWeek.Sunday);
DateTime endDay = startDay.AddDays(6);
string payPeriod = startDay.ToShortDateString() + " - " + endDay.ToShortDateString();
return payPeriod;
}