 
 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)


  opensAt

getQueriedDueAt = ->
  {due_at} = Router.currentQuery() # attempt to read the due date from query params
  TimeHelper.getMomentPreserveDate(due_at).format(TimeHelper.ISO_DATE_FORMAT) if due_at

getTaskPlanOpensAt = (planId) ->
  firstDueAt = _.first(TaskPlanStore.get(planId)?.tasking_plans)?.due_at

  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)
