 
 setPeriodDefaults = (courseId, planId, term) ->
   unless TaskingStore.hasTasking(planId)
-    if TaskPlanStore.isNew(planId) and not TaskingStore.hasTasking(planId)
-      due_date = getQueriedDueAt() or getTaskPlanOpensAt(planId)
-      TaskingActions.create(planId, {open_date: getQueriedOpensAt(planId, term.start), due_date})
+    if TaskPlanStore.isNew(planId)
+      due_date = getCurrentDueAt(planId) or getTaskPlanOpensAt(planId)
+      TaskingActions.create(planId, {open_date: getQueriedOpensAt(planId, due_date, term.start), due_date})
     else
       {tasking_plans} = TaskPlanStore.get(planId)
       TaskingActions.loadTaskings(planId, tasking_plans)

  else
    moment(now).add(1, 'day').format(TimeHelper.ISO_DATE_FORMAT)

getQueriedOpensAt = (taskPlanId, termStart) ->
  {opens_at} = Router.currentQuery() # attempt to read the open date from query params
  isNewPlan = TaskPlanStore.isNew(taskPlanId)
  opensAt = if opens_at and isNewPlan then TimeHelper.getMomentPreserveDate(opens_at)
  if not opensAt
    # default open date is tomorrow
    opensAt = getOpensAtDefault(termStart)

  # if there is a queried due date, make sure it's not the same as the open date
  dueAt = getQueriedDueAt()

  if dueAt?
    dueAtMoment = TimeHelper.getMomentPreserveDate(dueAt)
    # there's a corner case is certain timezones where isAfter doesn't quite cut it

  TaskingActions.loadDefaults(courseId, courseDefaults, periods)


module.exports = (planId, courseId, term) ->
  courseTimezone = CourseStore.getTimezone(courseId)
  TaskingActions.loadTaskToCourse(planId, courseId)
  loadCourseDefaults(courseId)

  #set the periods defaults only after the timezone has been synced
  return setPeriodDefaults(courseId, planId, term)
