return Range object set to this month

<code>
$range = Range::thisMonth( "EST" );
</code>

@param  string $timeZone User Time Zone
@return Range
327625
public static function thisMonth($timeZone = null)
    {
        $now = null;
        $before = null;
        if ( is_null($timeZone) ) {
            $now = new \DateTime();
            $before = new \DateTime();
        } else {
            $now = new \DateTime( "now", new \DateTimeZone( $timeZone ) );
            $before = new \DateTime( "now", new \DateTimeZone( $timeZone ) );
        }
        $dayOfMonth = $now->format( "j" );
        $offset = $dayOfMonth - 1;
        $before->modify( "-$offset day" );
        $range = new Range( $before, $now );

        return $range;
    }
1264125
public function getDatetime($data, $timezone = null)
    {
        if ($data instanceof \DateTime) {
            return $data;
        }

        if ($data instanceof \DateTimeImmutable) {
            return \DateTime::createFromFormat(\DateTime::ATOM, $data->format(\DateTime::ATOM));
        }

        // the format method accept array or integer
        if (is_numeric($data)) {
            $data = (int) $data;
        }

        if (\is_string($data)) {
            $data = strtotime($data);
        }

        $date = new \DateTime();
        $date->setTimestamp($data);
        $date->setTimezone(new \DateTimeZone($timezone ?: $this->timezoneDetector->getTimezone()));

        return $date;
    }
1205436
public static function factory($time = null, $timezone = null) {
        $timezone = static::timezone($timezone);

        if ($time instanceof DateTime) {
            return $time->setTimezone($timezone);
        }

        if (is_numeric($time)) {
            $time = '@' . $time;
        }

        $dt = new DateTime($time);
        $dt->setTimezone($timezone);

        return $dt;
    }
76864
private function offsetGmt(string $timezone): string
    {
        $offset = $this->offsetSeconds($timezone);
        $offset = gmdate('H:i', (int) $offset);

        return 'GMT'.($offset < 0 ? $offset : '+'.$offset);
    }
38906
public static function now(?string $timezone = null): Time
    {
        $timezone = $timezone ?: date_default_timezone_get();
        assert(Validate::isTimezone($timezone), sprintf('Invalid timezone: %s', $timezone));

        $dateTime = new DateTimeImmutable('now', new DateTimeZone($timezone));
        $hour = (int) $dateTime->format('G');
        $minute = (int) $dateTime->format('i');
        $second = (int) $dateTime->format('s');

        return new static($hour, $minute, $second);
    }
1035940
public function getCreatedAtDatetime(string $timezone = null): ?DateTime
    {
    	if ($this->created_at === null) {
    		return null;
	    }

        return new DateTime($this->created_at, new DateTimeZone($timezone ?? 'UTC'));
    }
854691
public function asMonth(DatespanRange $range = null)
    {
        $this->checkDefaultType(function() { return $this->default instanceof Month;}, Month::class);
        return $this->default;
    }
1126048
def get_date_range_this_year(now=None):
    """"""
    if now is None:
        now = datetime.datetime.now().date()
    if now.month <= settings.YEAR_TURNOVER_MONTH:
        date_start = datetime.datetime(now.year - 1, 8, 1)  # TODO; don't hardcode these values
        date_end = datetime.datetime(now.year, 7, 1)
    else:
        date_start = datetime.datetime(now.year, 8, 1)
        date_end = datetime.datetime(now.year + 1, 7, 1)
    return timezone.make_aware(date_start), timezone.make_aware(date_end)
552540
public static function getOffset($ts = 'now', $timezone = self::UTC, $target_timezone = self::UTC) {

		if (!self::isValidTimezone($timezone) || !self::isValidTimezone($target_timezone)) {
			return 0;
		}

		$dta = new DateTime(null, new DateTimeZone($timezone));
		$dtb = new DateTime(null, new DateTimeZone($target_timezone));

		if (is_int($ts)) {
			$dta->setTimestamp($ts);
			$dtb->setTimestamp($ts);
		} else {
			$dta->modify($ts);
			$dtb->modify($ts);
		}

		return $dtb->getOffset() - $dta->getOffset();
	}
657875
public function format($format, $timezone)
    {
        $date = clone $this->date;
        $date->setTimezone(new DateTimeZone($timezone));
        return $date->format($format);
    }
1223861
private function getMysqlTimeZoneOffset(string $timezone): string
    {
        $tzUtc = new \DateTimeZone('UTC');
        $tLocal = new \DateTimeZone($timezone);
        $timeUtc = new \DateTime('now', $tzUtc);
        $offsetSeconds = $tLocal->getOffset($timeUtc);
        $offsetHours = $offsetSeconds / 3600;
        $offsetHours = ($offsetHours < 0) ? $offsetHours * -1 : $offsetHours;
        $prefix = ($offsetSeconds < 0) ? '-' : '+';
        return $prefix . sprintf('%02d:00', $offsetHours);
    }
385941
public static function rangeThisMonth()
    {
        $currentMonth = date('Y-m-01', time());
        $currentMonthTs = self::toTs($currentMonth);

        return [$currentMonthTs, $currentMonthTs + (86400 * (date('t') - 1))];
    }
1269248
private function offsetSeconds(string $timezone): float
    {
        $dtz = new DateTimeZone($timezone);

        return $dtz->getOffset(new DateTime('now', $dtz));
    }
256189
public static function getCodeFromTimezone($sTimezone)
    {
        $aAbbreviations = \DateTimeZone::listAbbreviations();
        foreach ($aAbbreviations as $sCode => $aValues) {
            foreach ($aValues as $aValue) {
                if ($aValue['timezone_id'] == $sTimezone) {
                    return strtoupper($sCode);
                }
            }
        }

        return false;
    }
887473
protected function getTimezoneObject($timezone) {
		if(!isset($this->timezonesObjects[$timezone])) {
			$this->timezonesObjects[$timezone] = new \DateTimezone($timezone);
		}
		return $this->timezonesObjects[$timezone];
	}
363042
private static function parseTimeZone(string $timeZone): array
    {
        $parts = explode('/', $timeZone);

        if (count($parts) > 2) {
            return [$parts[0], $parts[1] . ' / ' . $parts[2]];
        }

        if (count($parts) > 1) {
            return [$parts[0], $parts[1]];
        }

        return ['Other', $parts[0]];
    }
101615
public static function now(?string $timezone = null): Date
    {
        $timezone = $timezone ?: date_default_timezone_get();
        assert(Validate::isTimezone($timezone), sprintf('Invalid timezone: %s', $timezone));

        $dateTime = new DateTimeImmutable('now', new DateTimeZone($timezone));
        $year = (int) $dateTime->format('Y');
        $month = (int) $dateTime->format('n');
        $day = (int) $dateTime->format('j');

        return new static($year, $month, $day);
    }