Skip to content

Commit fc3d828

Browse files
committed
🎉 created base project
0 parents  commit fc3d828

5 files changed

Lines changed: 263 additions & 0 deletions

File tree

.github/FUNDING.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These are supported funding model platforms
2+
3+
open_collective: leaf

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
test
2+
Experimental
3+
vendor
4+
composer.lock

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!-- markdownlint-disable no-inline-html -->
2+
<p align="center">
3+
<br><br>
4+
<img src="https://leaf-docs.netlify.app/images/logo.png" height="100"/>
5+
<h1 align="center">Leaf FileSystem Module</h1>
6+
<br><br>
7+
</p>
8+
9+
# Leaf PHP
10+
11+
[![Latest Stable Version](https://poser.pugx.org/leafs/fs/v/stable)](https://packagist.org/packages/leafs/fs)
12+
[![Total Downloads](https://poser.pugx.org/leafs/fs/downloads)](https://packagist.org/packages/leafs/fs)
13+
[![License](https://poser.pugx.org/leafs/fs/license)](https://packagist.org/packages/leafs/fs)
14+
15+
Leaf's core fs functionality packaged as a serve-yourself module.
16+
17+
## Installation
18+
19+
You can easily install Leaf using [Composer](https://getcomposer.org/).
20+
21+
```bash
22+
composer require leafs/fs
23+
```
24+
25+
## View Leaf's docs [here](https://leafphp.netlify.app/#/)
26+
27+
Built with ❤ by [**Mychi Darko**](https://mychi.netlify.app)

composer.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "leafs/fs",
3+
"description": "Leaf PHP session + flash modules",
4+
"keywords": [
5+
"fs",
6+
"filesystem",
7+
"files",
8+
"leaf",
9+
"php",
10+
"framework"
11+
],
12+
"homepage": "https://leafphp.netlify.app/#/",
13+
"type": "library",
14+
"license": "MIT",
15+
"authors": [
16+
{
17+
"name": "Michael Darko",
18+
"email": "mickdd22@gmail.com",
19+
"homepage": "https://mychi.netlify.app",
20+
"role": "Developer"
21+
}
22+
],
23+
"autoload": {
24+
"psr-4": {
25+
"Leaf\\": "src"
26+
}
27+
},
28+
"minimum-stability": "stable",
29+
"require": {
30+
"symfony/finder": "^5.3"
31+
}
32+
}

src/Date.php

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
<?php
2+
3+
namespace Leaf;
4+
5+
use \DateTime;
6+
7+
/**
8+
* Leaf Date
9+
* ----------------------
10+
* Quick date/time manipulation with Leaf
11+
*
12+
* @author Michael Darko
13+
* @since 1.1.0
14+
*/
15+
class Date
16+
{
17+
/**
18+
* Generate a random timestamp
19+
*/
20+
public static function randomTimestamp($start = 1149095981, $end = 1749095981)
21+
{
22+
$random = mt_rand($start, $end);
23+
return date("Y-m-d H:i:s", $random);
24+
}
25+
26+
/**
27+
* Generate a random date
28+
*/
29+
public static function randomDate($start = 1149095981, $end = 1749095981)
30+
{
31+
$timestamp = mt_rand($start, $end);
32+
$randomDate = new DateTime();
33+
$randomDate->setTimestamp($timestamp);
34+
$randomDate = json_decode(json_encode($randomDate), true);
35+
return $randomDate['date'];
36+
}
37+
38+
/**
39+
* Set default date timezone
40+
*/
41+
public static function setTimezone(String $timezone = "Africa/Accra")
42+
{
43+
date_default_timezone_set($timezone);
44+
}
45+
46+
/**
47+
* Set default date timezone
48+
*/
49+
public static function getTimezone()
50+
{
51+
return date_default_timezone_get();
52+
}
53+
54+
/**
55+
* Parse unix date
56+
*/
57+
public static function rawDate($date, $format = 'D, d M Y H:i:s')
58+
{
59+
return date($format, $date);
60+
}
61+
62+
/**
63+
* Return current date(timestamp)
64+
*/
65+
public static function now($useTFFormat = true)
66+
{
67+
return date($useTFFormat ? 'Y-m-d H:i:s' : 'Y-m-d h:i:s a', time());
68+
}
69+
70+
/**
71+
* Get the date a number of days ago
72+
*/
73+
public static function daysAgo(int $days_ago, $date = null)
74+
{
75+
return date('Y-m-d', strtotime("-$days_ago days", strtotime(self::toDate($date ?? self::now()))));
76+
}
77+
78+
/**
79+
* Get the date a number of months ago
80+
*/
81+
public static function monthsAgo(int $months_ago, $date = null)
82+
{
83+
return date('Y-m-d', strtotime("-$months_ago months", strtotime(self::toDate($date ?? self::now()))));
84+
}
85+
86+
/**
87+
* Get the date a number of years ago
88+
*/
89+
public static function yearsAgo(int $years_ago, $date = null)
90+
{
91+
return date('Y-m-d', strtotime("-$years_ago years", strtotime(self::toDate($date ?? self::now()))));
92+
}
93+
94+
/**
95+
* Convert a timstamp to a date
96+
*/
97+
public static function toDate($timestamp, $format = 'Y-m-d')
98+
{
99+
$timestamp = new DateTime($timestamp);
100+
$date = $timestamp;
101+
return $date->format($format);
102+
}
103+
104+
/**
105+
* Get a neatly formatted english date from a timestamp
106+
*/
107+
public static function toEnglishDate($timestamp)
108+
{
109+
$timestamp = new DateTime($timestamp);
110+
$day = $timestamp->format('d');
111+
$month = $timestamp->format('m');
112+
$month = ltrim($month, 0);
113+
$month = self::intToMonth($month);
114+
$year = $timestamp->format('Y');
115+
$date = $month . ' ' . $day . ', ' . $year;
116+
return $date;
117+
}
118+
119+
/**
120+
* Format a timestamp to an english readable of a timestamp
121+
*/
122+
public static function toEnglishTs($timestamp)
123+
{
124+
$timestampp = new DateTime($timestamp);
125+
$day = $timestampp->format('d');
126+
$month = $timestampp->format('m');
127+
$month = self::intToMonth(ltrim($month, '0'));
128+
$year = $timestampp->format('Y');
129+
$time = self::toTime($timestamp);
130+
$english_timeStamp = $day . ' ' . $month . ' ' . $year . ' ' . $time;
131+
return $english_timeStamp;
132+
}
133+
134+
/**
135+
* Get the time from a timestamp
136+
*/
137+
public static function toTime($ts)
138+
{
139+
$ts = new DateTime($ts);
140+
return $ts->format('G:i:s');
141+
}
142+
143+
/**
144+
* Format a TimeStamp
145+
*/
146+
public static function format($ts, $format = "Y-m-d")
147+
{
148+
$ts = new DateTime($ts);
149+
return $ts->format($format);
150+
}
151+
152+
/**
153+
* Get the current year
154+
*/
155+
public static function year()
156+
{
157+
return date('Y', time());
158+
}
159+
160+
/**
161+
* Get current month
162+
*/
163+
public static function month()
164+
{
165+
return date('m', time());
166+
}
167+
168+
/**
169+
* Get current day
170+
*/
171+
public static function day()
172+
{
173+
return date('m', time());
174+
}
175+
176+
/**
177+
* Get the month from a number
178+
*/
179+
public static function intToMonth(int $number)
180+
{
181+
$number = ltrim($number, '0');
182+
$months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
183+
$month = $months[$number - 1];
184+
return $month;
185+
}
186+
187+
/**
188+
* Get the day from a number
189+
*/
190+
public static function intToDay(int $number)
191+
{
192+
$number = ltrim($number, '0');
193+
$days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
194+
$day = $days[$number - 1];
195+
return $day;
196+
}
197+
}

0 commit comments

Comments
 (0)