Giter Club home page Giter Club logo

work-home-schedule's Introduction

Working Home Schedule

CI Coverage Status StyleCI

Installation

  • Download composer firstly:
curl -sS https://getcomposer.org/installer | php
  • Install lee/work-home-schedule secondly:
php composer.phar require lee/work-home-schedule:^1

Introduction

This is about working home schedule to estimate current working status on specific date.

It's based on following scenario for A/B team work:

  • A team work from office today, and B team will work from home today.
  • A team work from home tomorrow, and B team will work from office tomorrow.
  • And so on.

This situation will skip on country holiday and weekend.

Usage

This class depends on Carbon::mixin method.

The code snippets are as follows:

  • Set startDateStatus about working from home or office.
  • Set csvPath about specific CSV file path.
  • Set csvHead about whether CSV file path has head.
  • Loading calendar data, the calendar CSV format is available here.

We assume that the 2020-04-06 is start date and working statuses are as follows:

  • The start date status is office.

Get next working date about code snippets are as follows:

require __DIR__ . '/vendor/autoload.php';

use Carbon\Carbon;
use Lee\WorkHomeSchedule;

$filePath = __DIR__ . '/tests/fixtures/2020_calendar.csv';

$workingHomeSchedule = new WorkHomeSchedule();
$workingHomeSchedule->startDateStatus = 'office'; // The default value is empty string
$workingHomeSchedule->csvPath = $filePath; // The default value is empty string
$workingHomeSchedule->csvHead = true; // The default value is true

$workingHomeSchedule = $workingHomeSchedule->loadCalendarData($filePath);

Carbon::mixin($this->workingHomeSchedule);
$currentDate = Carbon::create('2020-04-06');

$nextWorkingDate = $currentDate->nextWorkingDate();

$carbonDate = $nextWorkingDate['date']; // Carbon::class instance
$carbonDateString = (string)$nextWorkingDate['date']; // 2020-04-07 00:00:00
$workingStatus = $nextWorkingDate['status']; // home

Get previous working date about code snippets are as follows:

require __DIR__ . '/vendor/autoload.php';

use Carbon\Carbon;
use Lee\WorkHomeSchedule;

$filePath = __DIR__ . '/tests/fixtures/2020_calendar.csv';

$workingHomeSchedule = new WorkHomeSchedule();
$workingHomeSchedule->startDateStatus = 'office'; // The default value is empty string
$workingHomeSchedule->csvPath = $filePath; // The default value is empty string
$workingHomeSchedule->csvHead = true; // The default value is true

$workingHomeSchedule = $workingHomeSchedule->loadCalendarData($filePath);

Carbon::mixin($this->workingHomeSchedule);
$currentDate = Carbon::create('2020-04-06');

$previousWorkingDate = $currentDate->previousWorkingDate();

$carbonDate = $previousWorkingDate['date']; // Carbon::class instance
$carbonDateString = (string)$previousWorkingDate['date']; // 2020-04-01 00:00:00
$workingStatus = $previousWorkingDate['status']; // home

Get next working dates with specific date ranges about code snippets are as follows:

require __DIR__ . '/vendor/autoload.php';

use Carbon\Carbon;
use Lee\WorkHomeSchedule;

$filePath = __DIR__ . '/tests/fixtures/2020_calendar.csv';

$workingHomeSchedule = new WorkHomeSchedule();
$workingHomeSchedule->startDateStatus = 'office'; // The default value is empty string
$workingHomeSchedule->csvPath = $filePath; // The default value is empty string
$workingHomeSchedule->csvHead = true; // The default value is true
$workingHomeSchedule->workingDays = 2; // The default value is 1

$workingHomeSchedule = $workingHomeSchedule->loadCalendarData($filePath);

Carbon::mixin($this->workingHomeSchedule);
$currentDate = Carbon::create('2020-04-06');

$nextWorkingDates = $currentDate->nextWorkingDates(); // The array length is 2

$nextWorkingDates[0]['date'] // Carbon::class instance
(string)$nextWorkingDates[0]['date'] // 2020-04-07 00:00:00
$nextWorkingDates[0]['status'] // home

$nextWorkingDates[1]['date'] // Carbon::class instance
(string)$nextWorkingDates[1]['date'] // 2020-04-08 00:00:00
$nextWorkingDates[1]['status'] // office

Get previous working dates with date ranges about code snippets are as follows:

require __DIR__ . '/vendor/autoload.php';

use Carbon\Carbon;
use Lee\WorkHomeSchedule;

$filePath = __DIR__ . '/tests/fixtures/2020_calendar.csv';

$workingHomeSchedule = new WorkHomeSchedule();
$workingHomeSchedule->startDateStatus = 'office'; // The default value is empty string
$workingHomeSchedule->csvPath = $filePath; // The default value is empty string
$workingHomeSchedule->csvHead = true; // The default value is true
$workingHomeSchedule->workingDays = 2; // The default value is 1

$workingHomeSchedule = $workingHomeSchedule->loadCalendarData($filePath);

Carbon::mixin($this->workingHomeSchedule);
$currentDate = Carbon::create('2020-04-06');

$previousWorkingDates = $currentDate->previousWorkingDates(); // array length is 2

$previousWorkingDates[0]['date'] // Carbon::class instance
(string)$previousWorkingDates[0]['date'] // 2020-04-01 00:00:00
$previousWorkingDates[0]['status'] // home

$previousWorkingDates[1]['date'] // Carbon::class instance
(string)$previousWorkingDates[1]['date'] // 2020-03-31 00:00:00
$previousWorkingDates[1]['status'] // office

work-home-schedule's People

Contributors

peter279k avatar

Stargazers

 avatar

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.