GithubHelp home page GithubHelp logo

Comments (4)

fightbulc avatar fightbulc commented on May 11, 2024

Hey Takumi. Will take a look asap. Also, are u able to add a Japanese translation?

from moment.php.

takumi-dev avatar takumi-dev commented on May 11, 2024

Hi fightbulc, I've made a translation.
I will be glad if it helps you.

Thanks for your developing.

from moment.php.

fightbulc avatar fightbulc commented on May 11, 2024

@takumi-dev, I hope you don't do all these transformations you put up there as your test code. Do you have a real-world example where you don't get the expected result?

from moment.php.

takumi-dev avatar takumi-dev commented on May 11, 2024

@fightbulc, Sure. So far no problem for my product.
I just call endOf('month') twice. I don't know why it works, but it works.

Here is a real-world example.

$rows = array();

$start = '2016-01-31';
$end = '2016-04-30';

$timezone = 'Asia/Tokyo';
$subjectFormat = __('for %s~%s');
$dateFormat = __('Y-m-d');

$now = new \Moment\Moment($start, $timezone);
$until = new \Moment\Moment($end, $timezone);

$now->subtractDays(1);
$noDate = false;
while( $now->isBefore($until) )
{
    $now->addDays(1)->startOf('day');
    $next = $now->cloning()->startOf('month');
    if( (string)$now->getDay() === '01' )
    {
        $next->endOf('month');
        if( $noDate )
        {
            $next->setDay($until->getDay());
            $noDate = false;
        }
    }
    else
    {
        $next->addMonths(1)->setDay($until->getDay());
        if( $next->getDay() !== $until->getDay() )
        {
            $next->subtractMonths(1)->endOf('month');
        }
        if( $next->cloning()->endOf('month')->format() === $next->format() )
        {
            $noDate = true;
        }
    }

    $subject = sprintf($subjectFormat, $now->format(__('m/d')), $next->format(__('m/d')));
    $rows []= $subject;

    $now = $next;
}
print_r($rows);

/*
*  expected: Array ( [0] => for 01/31~02/29 [1] => for 03/01~03/30 [2] => for 03/31~04/30 )
*  real:     Array ( [0] => for 01/31~02/28 [1] => for 02/29~03/30 [2] => for 03/31~04/30 )
*/

These codes are for generating rows of a document for kind of estimation.
usage:
for 01/31-02/29 $100
for 03/01~03/30 $150

from moment.php.

Related Issues (20)

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.