• 根据用户选择年月日的类型,分别计算各种类型下的时间跨度


    Sub 'dotime'

    //当意向租赁日期改变时候,重新计算意向租期
    if not &Intention.IntentionStartDate.IsEmpty() and not &Intention.IntentionEndDate.IsEmpty()
    &Yend=&Intention.IntentionEndDate.Year()
    &Ystart=&Intention.IntentionStartDate.Year()
    &Mend=&Intention.IntentionEndDate.Month()
    &Mstart=&Intention.IntentionStartDate.Month()
    &Dend=&Intention.IntentionEndDate.Day()
    &Dstart=&Intention.IntentionStartDate.Day()
    &Y=&Yend-&Ystart

    &idate=&Intention.IntentionEndDate-&Intention.IntentionStartDate+1
    if &idate<1
    msg('结束日期必须大于开始日期')
    &Intention.IntentionTenancy=''
    else

    Do Case
    //1:m2/天 2:m2/月 3:m2/年
    Case &Intention.IntentionUnitID=1
    &Intention.IntentionTenancy=&idate.ToString()+'天'

    Case &Intention.IntentionUnitID=2
    //创建变量,存储租赁开始时间
    &temp=&Intention.IntentionStartDate
    //创建比租赁截至时间小一月的时间,用于do循环
    &etemp=&Intention.IntentionEndDate.AddMonths(-1)
    &i=0
    Do while &temp<=&etemp
    &temp=&temp.AddMonths(1)
    &i=&i+1
    Enddo
    //有两种情况,需要把月数+1,天数清0.
    //1.租赁租期最后一个月刚好是自然月
    &addDay=&Intention.IntentionEndDate.AddDays(1)
    &newMonth=&addDay.Month()
    if &Dstart=1 and &newMonth-&Mend=1
    &i=&i+1
    &Intention.IntentionTenancy=&i.ToString().Trim()+'月'
    else
    //当自然月刚好是12月的特殊情况
    if &Dstart=1 and &Mend=12 and &Dend=31
    &i=&i+1
    &Intention.IntentionTenancy=&i.ToString().Trim()+'月'
    else
    //2.租赁最后一个月刚好是顺延月
    if &Mend-&Mstart=1 and &Dstart-&Dend=1
    &i=&i+1
    &Intention.IntentionTenancy=&i.ToString().Trim()+'月'
    else
    //处理刚好是整年的情况
    if not &Yend-&Ystart=0 and &Mend=&Mstart and &Dstart-&Dend=1
    //记录差的年数的总月数
    &Ytemp=(&Yend-&Ystart)*12
    &Intention.IntentionTenancy=&Ytemp.ToString().Trim()+'月'
    else
    //计算不足一月的天数
    &idate=&Intention.IntentionEndDate-&temp+1
    &Intention.IntentionTenancy=&i.ToString().Trim()+'月'+&idate.ToString().Trim()+'天'
    endif
    endif
    endif
    endif

    Case &Intention.IntentionUnitID=3
    //创建变量,存储租赁开始时间
    &temp=&Intention.IntentionStartDate
    //创建比租赁截至时间小一年的时间,用于do循环
    &etemp=&Intention.IntentionEndDate.AddYears(-1)
    //创建顺延时间对象
    Do while &temp<=&etemp
    &temp=&temp.AddYears(1)
    Enddo
    //通过顺延时间计算租赁的整数年
    &Y=(&temp-&Intention.IntentionStartDate)/365
    //计算不足一年的天数
    &idate=&Intention.IntentionEndDate-&temp+1
    //顺延年的处理
    &newDate=&Intention.IntentionEndDate.AddDays(1)
    if not &Yend-&Ystart=0 and &newDate.Month()=&Mstart and &Dstart=&newDate.Day()
    &diff=(&Intention.IntentionEndDate-&Intention.IntentionStartDate+1)/365
    &Intention.IntentionTenancy=&diff.ToString().Trim()+'年'
    else
    //刚好自然年的时候处理
    if &Mstart=1 and &Dstart=1 and &Mend=12 and &Dend=31
    &Y=&Y+1
    &Intention.IntentionTenancy=&Y.ToString().Trim()+'年'
    else
    //顺延年的特殊处理
    if not &Yend-&Ystart=0 and &Mend=&Mstart and &Dstart-&Dend=1
    &Y=&Y+1
    &Intention.IntentionTenancy=&Y.ToString().Trim()+'年'
    else
    &Intention.IntentionTenancy=&Y.ToString()+'年'+&idate.ToString().Trim()+'天'
    endif
    endif
    endif

    Otherwise
    msg('请选择有效租期单位')
    Endcase
    endif

    else
    msg('请选择租赁开始和结束日期')
    &Intention.IntentionUnitID=-1
    endif

    EndSub

  • 相关阅读:
    栈和队列
    链表
    map
    二叉平衡树旋转
    二叉排序树详情
    红黑树详情
    查并集
    动态规划
    位操作
    字典树
  • 原文地址:https://www.cnblogs.com/metu/p/10826354.html
Copyright © 2020-2023  润新知